views:

215

answers:

1

I have some code here:

(...)
NSURLConnection *theConnection = [[NSURLConnection alloc] 
                initWithRequest:theRequest delegate:self];
if( theConnection )
{
    webData = [[NSMutableData data] retain];
}

and delegate methods:

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{   
    NSLog(@"zero");
   [webData setLength: 0];
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    NSLog(@"got %d", [data length]);
    [webData appendData:data];
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    NSLog(@"ERROR with theConenction");
    [connection release];
    [webData release];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{

    NSLog(@"DONE. Received Bytes: %d", [webData length]);
    [connection release];
    [webData release];      
}

It works pretty good untill more data has to come. Than NSURLConnection "stop working" (with no error, no exception, no quit). I can still use my app. I noticed that problem begin when didReceiveData is being called more than once during the connection.

How it looks like step by step from debugger:

1. I call theRequest
2. Delegate call didReceiveResponse

2010-06-21 18:10:16.708 MyApp[9477:207] zero

3. Delegate call didReceiveData

2010-06-21 18:10:16.709 MyApp[9477:207] got 6912

(gdb) continue

4. Delegate call didReceiveData (once again)

2010-06-21 18:10:18.027 MyApp[9477:207] got 114067

(gdb) continue

--> and here is the problem <--

main loop continue with no breakpoint, and connectionDidFinishLoading is not called. Everything is ok when didRecieveData is being called just once.

5. Delegate call didFailWithError (after 5 min!)

2010-06-21 18:15:18.041 MyApp[9477:207] ERROR with theConenction Connection failed! Error - The operation couldn’t be completed. Connection reset by peer

(gdb) continue

=============== UPDATE ====================

Finally, I have discovered one important thing: True problem is that remote host doesn't finish connection in proper way sometimes (ie. big amount of data), so delegate connectionDidFinishLoading can't be called and after 5 min remote host reset connection.

Has anyone the problem too and can help?

A: 

If you put on breakpoints, does say where it has stopped?

UK-AL
there are breakpoints, but after some loops it freezes with no reaction on breakpoint and XCode notice bar shows "Running..." But what is important the main thread of the program doesn't freze - I can use my app
falkon