3

I am using server client architecture in my application.

I am using NSURLConnection class,now suppose i am sending multiple requests in for loop and using async connection with delegate methods.So my question is after I got response from server do I need to close connection manually and make that object null.

I am asking because on server there is constraint on maximum connections to be made and if that connection limit exceeds I have to restart server and I can not change maximum connection limit.

Vaibhav
  • 865
  • 2
  • 10
  • 19

3 Answers3

2

No. It is not needed as NSURLConnection will close the connection by itself when an error occurs or the data has loaded.

If you wish to monitor what actually happens, I suggest looking at Technical Q&A QA1176. It describes how you can set up an environment to monitor each packet that is sent by an iPhone. Then you can verify the behavior of NSURLConnection yourself.

Mats
  • 8,528
  • 1
  • 29
  • 35
1

The proper way to release the connection is to set it to be nil along with the property used to receive data from the connection:

theConnection = nil;
receivedData = nil;

This is from the URL Session Programming Guide in the section Using NSURLConnection.

Release the connection and the data object by setting the properties (declared elsewhere) to nil. Note that a real-world app usually requires the delegate to manage more than one connection at a time, so these lines would typically be replaced by code to iterate through whatever data structures you are using.

Daniel Zhang
  • 5,778
  • 2
  • 23
  • 28
0

Please used this..may be helped

[self.connection cancel];
self.connection = nil;
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
Kiran K
  • 919
  • 10
  • 17