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?