Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1016953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:37:38+00:00 2026-05-16T10:37:38+00:00

I am writing a code that reads data from a http connection and stores

  • 0

I am writing a code that reads data from a http connection and stores in a byte array.
I have written my own NSOperation class. Reference of the code is

Concurrent Operations Demystified

My HttpWorker class declaration is like

@interface HttpWorker : NSOperation{

    NSString *param;
    double requestCode;
    BOOL isLive;
    long initSleep;
    BOOL _isFinished;
    BOOL _isExecuting;
    NSURL *_url;
    NSURLConnection *_connection;
    NSData *_data;


}

@property (nonatomic, retain) NSString *param;
@property (nonatomic) double requestCode;
@property (nonatomic) BOOL isLive;
@property (nonatomic) long initSleep;
@property (readonly) BOOL isFinished;
@property (readonly) BOOL isExecuting;
@property (readonly, copy) NSURL *url;
@property (nonatomic, retain) NSURLConnection *httpCon;
@property (readonly, retain) NSData *data;



-(id)initWithUrl:(NSURL *)_url;
-(void) setRequestParameters:(NSString *)parameters iRequestCode:(double)iRequestCode initialSleep:(long)initialSleep;

@end

And my HttpWorker.m class is like

#import "HttpWorker.h"
#import "Resources.h"


@implementation HttpWorker

@synthesize param;
@synthesize requestCode;
@synthesize isLive;
@synthesize initSleep;
@synthesize isFinished = _isFinished;
@synthesize isExecuting = _isExecuting;
@synthesize url = _url;
@synthesize data = _data;


-(id) initWithUrl: (NSURL *)Url{
    self = [super init];
    if(self == nil){
        return nil;
    }
    _url = [Url copy];
    _isExecuting = NO;
    _isFinished = NO;
    return self;
}

-(BOOL) isConcurrent{
    return YES;
}

-(void) start{
    if(![NSThread isMainThread]){
        [self performSelectorOnMainThread:@selector(start) withObject:nil waitUntilDone:NO];
        return;
    }
    [self willChangeValueForKey:@"isExecuting"];
    _isExecuting = YES;
    [self didChangeValueForKey:@"isExecuting"];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:_url];
    NSLog(@"Connecting... %@",_url);
    _connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately: YES];
    if(_connection == nil){
        NSLog(@"connection is nil");
    }
}


-(void) setRequestParameters:(NSString *)parameters iRequestCode:(double)iRequestCode initialSleep:(long)initialSleep {
    self.param = parameters;
    self.requestCode = iRequestCode;
    self.initSleep = initialSleep;
}

/////////////////////////// delegate methods ///////////////////////////////

-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    NSLog(@"receieved response...");
    _data = [[NSData alloc] init];
}


-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)incomingData {
    NSLog(@"receieved data...");
}


-(void) connectionDidFinishLoading:(NSURLConnection *) connection {
    NSLog(@"connection did finish loading...");
}


@end

Problem is that when i run this code and add httpworker object to the NSOperationQueue, the code runs successfully and _connection is not nil but none of the delegate methods is executed. Can anyone please help?

Thanks and Best Regards…

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:37:39+00:00Added an answer on May 16, 2026 at 10:37 am

    Your delegate for the connection is “self” (= your NSOperation object). I assume this object is already gone when the connection wants to send messages to the delegate.

    Your NSOperation does not have a “main” implementation. Consequently nothing will happen after the thread is started. It will (asynchronously!) fire the NSOperation and quit.

    See:
    http://developer.apple.com/mac/library/documentation/Cocoa/Reference/NSOperation_class/Reference/Reference.html#//apple_ref/occ/instm/NSOperation/main


    Bottom line: I highly recommend ASIHTTPRequest for this kind of task.

    http://allseeing-i.com/ASIHTTPRequest/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm am writing a bit of python code that gets data from a website.
I am writing a FORTRAN program that reads data from a text file and
I'm using c#. In many cases I'm writing code that can benefit from a
I have a friend that wants to incrementally move data from one db to
I'm writing a simplistic HTTP server that will accept PUT requests mostly from cURL
I'm writing some quick code to try and extract data from an mp3 file
I am writing an application in C# that reads info from a .mdb file
I have written a program that reads in a File object (really an XML
I am currently writing a program that reads records from a txt file and
I am writing an Android app that connects to a Bluetooth device, reads data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.