Long polling with NSURLConnection

Posted by pix0r on Stack Overflow See other posts from Stack Overflow or by pix0r
Published on 2009-07-13T16:34:16Z Indexed on 2010/05/07 15:58 UTC
Read the original article Hit count: 257

Filed under:
|
|

I'm working on an iPhone application which will use long-polling to send event notifications from the server to the client over HTTP. After opening a connection on the server I'm sending small bits of JSON that represent events, as they occur. I am finding that -[NSURLConnectionDelegate connection:didReceiveData] is not being called until after I close the connection, regardless of the cache settings I use when creating the NSURLRequest. I've verified that the server end is working as expected - the first JSON event will be sent immediately, and subsequent events will be sent over the wire as they occur. Is there a way to use NSURLConnection to receive these events as they occur, or will I need to instead drop down to the CFSocket API?

I'm starting to work on integrating CocoaAsyncSocket, but would prefer to continue using NSURLConnection if possible as it fits much better with the rest of my REST/JSON-based web service structure.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c