1

My goal is to research about the limitaitons of iOS when it come to implementing a persistent connection.

Lets say I'm going to use NSURLConnection as my http client.

How many tcp connections can I hold open at the same time to a single host? How many tcp connections can I hold open to different hosts?

What is the default value and how do I change it?

Glenn S
  • 697
  • 9
  • 21
  • See here: http://stackoverflow.com/questions/2332741/what-is-the-theoretical-maximum-number-of-open-tcp-connections-that-a-modern-lin – Ramy Al Zuhouri Dec 21 '12 at 00:09
  • but that's a modern linux box thread? It probably is different to an iOS device? – Glenn S Dec 21 '12 at 00:20
  • 1
    @extremedurability Apple uses limit of four in their apps (see [MVCNetworking](http://developer.apple.com/library/ios/#samplecode/MVCNetworking)). I've seen claims online of 4-6 limit, but all of my tests have suggested 5. Doing benchmarking, I found the performance benefit diminishes as number of connections increases beyond 4. And given the serious hit on your server if you had lots of clients simultaneously doing more than that, 4 seems like a prudent limit. Why would you need more? – Rob Apr 03 '13 at 23:44
  • 1
    @Rob Thank you for answering, actually yes I also did some test in code(printing the number of open connection etc) and found out that it reaches only about 4-5 but I myself really can't confirm if my test is accurate and found not much information in the internet regarding this matter, so I didn't post it as an answer. I'm really glad that you also tried it and came up with same results. Actually we only need like 2 or 3 open connections, since we are tasked to optimized network connections of an instant messaging like app. eg: 1 connection for the IM server, for ads, and for polling – Glenn S Apr 04 '13 at 03:21

2 Answers2

0

In the simulator from my test, at least 10 connections(even more if you set the connections per host) that you can build for a single host.

But in the device, it seems just allow only one connection, because I build more than one connection, other connections maybe get the wrong response from server, it's very strange. so I think in the device only support one connection, but I can't any documents about this either, maybe I'm doing the wrong test in the device, but hope this will help you.

regrecall
  • 521
  • 1
  • 6
  • 20
  • 1
    Device definitely supports more than one concurrent connection. Many of us do concurrent requests all the time on devices without incident. It's integral feature of `AFNetworking` and I've done it in my own classes, too. I've seen claims of limit of 4-6 max concurrent requests to single host. I use 4 all the time and never have had problems. When I exceed five (with my server, at least), those additional requests will be suspended for up to one minute waiting for other requests to finish, so you generally need very slow network or very large files to experience the problem. – Rob Apr 03 '13 at 23:11
0

The maximum number of simultaneous connections to make to a given host default value is 6 in macOS, or 4 in iOS.

You can refer https://developer.apple.com/documentation/foundation/nsurlsessionconfiguration/1407597-httpmaximumconnectionsperhost

RaviYadav
  • 97
  • 1
  • 7