Rectangle 27 2

NSURLConnection is not keeping the connection alive forever; it has a timeout and if no data is received within that timeout, it closes the connection again.

The didReceiveData is only called when there is actually data available - if you send the request and nothing comes back from the server as there is no data currently available, it is expected that it is not called, isn't it?

Is the connectionDidFinishLoading method called? If it is called, I guess NSURLConnection was waiting for data a certain amount of time and as no data arrived, it stopped - as this method should always be called once NSURLConnection is done, no matter if it was successful or not.

A NSURLConnection bases on a NSURLRequest and when creating a NSURLRequest, you can manually set a timeout. Try setting a really huge timeout. Timeout is in seconds (fractions of seconds are allowed, it is a floating point number), so try setting 28800.0 as timeout, that is 8 hours and see if the connection now stays open long enough so didReciveData is ever called.

Please also note that NSURLConnection doesn't know where data starts and where data ends, so it might call didReceiveData multiple times for a single piece of data being sent and your app needs to re-assemble the received data itself and it must know if this is a full data block, ready for processing, or if it must wait for more data coming in another didReceiveData callback.

NSURLConnection does not guarantee to deliver data as soon as the data arrived. If it receives some data and it still has room to cache more data, it will keep waiting for more data and aggregate data into a chunk and finally deliver the whole chunk at once. That is why your countdown timer does not work. It does deliver all countdown data, but it does so after the countdown is over, as all the small countdown updates perfectly fit into a single chunk and further the MIME type of the HTTP header announces that many small chunks are following. To avoid calling your method delegate more often than necessary, NSURLConnection caches reply content internally as long as it still has room for doing so.

I'm not sure if you can do what you are trying to do with a NSURLConnection. I personally would rather use a real socket connection for that - but I don't know if that is possible on the iPhone.

In case it is any solace to you, the URL you posted here works nicely in Firefox, but it does not work in Safari 4 (Safari 4 only shows the image at the end, not the countdown). So the behavior you are getting here is the same one you get in Safari.

Hi, Thanks a lot for reply. I am stuck here. Can you please help with this situation? Can CFHTTPStream will resolve this problem? Is there any other way to work with this problem ? Thanks.

CFHTTP seems to be the same as the NS-Classes, just for Carbon (C instead of Obj-C), I doubt they will behave any different. You need to open a raw socket connection (CFSocket) and parse all HTTP and MIME headers yourself if you must have access to data as soon as it arrives. Do you have control over the server side? E.g. can you alter the way the server sends out the data? Or do you only have control over the client side?

HTTP connection with NSURLConnection in iphone - Stack Overflow

iphone http nsurlconnection
Rectangle 27 1

HttpParams httpParameters = new BasicHttpParams();
            HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1);
            HttpProtocolParams.setContentCharset(httpParameters,
                    HTTP.DEFAULT_CONTENT_CHARSET);
            HttpProtocolParams.setUseExpectContinue(httpParameters, true);

            // Set the timeout in milliseconds until a connection is
            // established.
            // The default value is zero, that means the timeout is not used.
            int timeoutConnection = 35 * 1000;
            HttpConnectionParams.setConnectionTimeout(httpParameters,
                    timeoutConnection);
            // Set the default socket timeout (SO_TIMEOUT)
            // in milliseconds which is the timeout for waiting for data.
            int timeoutSocket = 30 * 1000;
            HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

How to set HttpResponse timeout for Android in Java - Stack Overflow

java android timeout httpresponse
Rectangle 27 2

The client will close the connection when it does not receive any data for a certain time. This timeout cannot be influenced by HTTP headers. It is client-specific and usually set to 120 seconds IIRC.

So all you have to do is send small amounts of data regularly to avoid hitting the timeout.

php - How to display HTML to the browser incrementally over a long per...

php xmlhttprequest comet
Rectangle 27 9

//username and password value
NSString *username = @your_username;
NSString *password = @your_password;

//HTTP Basic Authentication
NSString *authenticationString = [NSString stringWithFormat:@"%@:%@", username, password]];
NSData *authenticationData = [authenticationString dataUsingEncoding:NSASCIIStringEncoding];
NSString *authenticationValue = [authenticationData base64Encoding];

//Set up your request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.your-api.com/]];

// Set your user login credentials
[request setValue:[NSString stringWithFormat:@"Basic %@", authenticationValue] forHTTPHeaderField:@"Authorization"];

// Send your request asynchronously
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *responseCode, NSData *responseData, NSError *responseError) {
      if ([responseData length] > 0 && responseError == nil){
            //logic here
      }else if ([responseData length] == 0 && responseError == nil){
             NSLog(@"data error: %@", responseError);
             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Error accessing the data" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
             [alert show];
             [alert release];
      }else if (responseError != nil && responseError.code == NSURLErrorTimedOut){
             NSLog(@"data timeout: %@, NSURLErrorTimedOut);
             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"connection timeout" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
             [alert show];
             [alert release];
      }else if (responseError != nil){
             NSLog(@"data download error: %@,responseError);
             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"data download error" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
             [alert show];
             [alert release];
      }
}]

The method base64Encoding you are using to convert NSData to NSString is now deprecated: - (NSString *)base64Encoding NS_DEPRECATED(10_6, 10_9, 4_0, 7_0); Better to use NSDataBase64Encoding category instead.

iphone - NSURLConnection and Basic HTTP Authentication in iOS - Stack ...

ios iphone objective-c nsurlconnection
Rectangle 27 9

//username and password value
NSString *username = @your_username;
NSString *password = @your_password;

//HTTP Basic Authentication
NSString *authenticationString = [NSString stringWithFormat:@"%@:%@", username, password]];
NSData *authenticationData = [authenticationString dataUsingEncoding:NSASCIIStringEncoding];
NSString *authenticationValue = [authenticationData base64Encoding];

//Set up your request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.your-api.com/]];

// Set your user login credentials
[request setValue:[NSString stringWithFormat:@"Basic %@", authenticationValue] forHTTPHeaderField:@"Authorization"];

// Send your request asynchronously
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *responseCode, NSData *responseData, NSError *responseError) {
      if ([responseData length] > 0 && responseError == nil){
            //logic here
      }else if ([responseData length] == 0 && responseError == nil){
             NSLog(@"data error: %@", responseError);
             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Error accessing the data" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
             [alert show];
             [alert release];
      }else if (responseError != nil && responseError.code == NSURLErrorTimedOut){
             NSLog(@"data timeout: %@, NSURLErrorTimedOut);
             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"connection timeout" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
             [alert show];
             [alert release];
      }else if (responseError != nil){
             NSLog(@"data download error: %@,responseError);
             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"data download error" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
             [alert show];
             [alert release];
      }
}]

The method base64Encoding you are using to convert NSData to NSString is now deprecated: - (NSString *)base64Encoding NS_DEPRECATED(10_6, 10_9, 4_0, 7_0); Better to use NSDataBase64Encoding category instead.

iphone - NSURLConnection and Basic HTTP Authentication in iOS - Stack ...

ios iphone objective-c nsurlconnection
Rectangle 27 0

The issue may come from the connection timeout when trying to get a huge amount of data from your database, so trying to set the connection timeout in your code as below:

.net 4.0 - Entity Framework: Calling 'Read' when DataReader is closed ...

entity-framework .net-4.0
Rectangle 27 0

The issue may come from the connection timeout when trying to get a huge amount of data from your database, so trying to set the connection timeout in your code as below:

.net 4.0 - Entity Framework: Calling 'Read' when DataReader is closed ...

entity-framework .net-4.0
Rectangle 27 0

/**
* Creates instance of HttpTransportSE with set url
*
* @param url
* the destination to POST SOAP data
* @param timeout
* timeout for connection and Read Timeouts (milliseconds)
*/
    public HttpTransportSE(String url, int timeout) {
        super(url, timeout);
    }
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 60 * 1000); // 60 sec

web services - Need help in parsing soap webservice in android - Stack...

web-services soap wsdl ksoap2 soap-client