views:

93

answers:

2

I have a small bug in my client app that uses NSURLConnection. I have tracked it down to an unexpected connection keep-alive that seems to confuse the web server (probably a bug on the server side). The workaround would be to force-close all outstanding connections at a certain point. Can I do this somehow with NSURLConnection, i.e. something like

[NSURLConnection closeAllIdleConnections];

A: 

I think you might want to look at the following method defined for NSURLConnections. This assumes that you made the call asynchronously. If it isn't an async call, then it probably should be.

cancel Cancels an asynchronous load of a request.

  • (void)cancel

Discussion Once this method is called, the receiver’s delegate will no longer receive any messages for this NSURLConnection.

Hope this helps. Andrew.

Andrew Little
Thank you, I tried cancelling the connection once it ended, but it doesn't seem to work that way (kind of logical, I would guess...). The problem is of course that I don't want to cancel the request, but close the connection. I guess I failed to outsmart NSURLConnection...
Krumelur
A: 

ASIHTTPRequest has an expirePersistentConnections method. It may do what you're looking for.

It's not a drop-in replacement for NSURLConnection, but it's not too hard to port code from NSURLConnection to ASIHTTPRequest.

Robot K
Good tip. Thanks!
Krumelur