On May 29, 2010, at 11:53 AM, Nava Carmon wrote: > When I initialize the NSURLConnection I define a timeout in my > NSURLMutableRequest in order not to stuck the GUI and let the user to work > with application. On timeout I get didFailWithError in > NSURLConnectionDelegate and show a message that there was not response from > the server and the user can continue working.
If you’re running the NSURLConnection asynchronously (which I think you are, since you use a delegate), you can already unblock the UI and let the user continue to work. That’s a better design than waiting until the connection finishes, especially in a mobile app. (For example, my Twitter client returns to the timeline as soon as I press the Post button, and sends the post to the Twitter servers in the background.) > The matter is that the connection or underlying socket somehow is preserved > and the connection with the server is not closed. So when I try to get > another url from the same server I can't reach it since the server is still > stuck with the previous problematic request! Hm. It’s true that CFNetwork uses HTTP keep-alive mode, where it can reuse a socket for multiple requests. But I don’t think it’ll send a second request on the same socket until the previous one is complete. (I.e. I don’t believe it supports pipelining.) Instead it should be opening a new socket while the first one is busy, up to a max of I think 4 sockets per host. I don’t know if there’s any way, using public API, to disable keep-alive. It’s possible using a lower-level API like CFStream would let you get around this. I would ask on the macnetworkprog list. (And make sure to mention that this is on iPhone, as the APIs aren’t exactly the same as on Mac.) > Each time I need to get xml file I create another NSURLConnection. I read > somewhere that it's not a good practice… No, that’s fine. The API was designed so that one connection = one request; note that there’s no way to re-use a NSURLConnection object for a second request. Under the hood the CFNetwork framework will be as efficient as it can, by re-using sockets when possible. —Jens _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com