Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的目标是研究 iOS 在实现持久连接时的局限性。
假设我将使用 NSURLConnection 作为我的 http 客户端。
我可以同时打开多少个 tcp 连接到单个主机?我可以为不同的主机打开多少个 tcp 连接?
默认值是什么,如何更改它?
在我测试的模拟器中,您可以为单个主机构建至少 10 个连接(如果您为每个主机设置连接,则更多)。
但是在设备中,似乎只允许一个连接,因为我建立了多个连接,其他连接可能会得到服务器的错误响应,这很奇怪。所以我认为设备中只支持一个连接,但我也没有任何关于这个的文档,也许我在设备中做错了测试,但希望这会对你有所帮助。
与给定主机默认值建立的最大同时连接数在 macOS 中为 6,在 iOS 中为 4。
您可以参考https://developer.apple.com/documentation/foundation/nsurlsessionconfiguration/1407597-httpmaximumconnectionsperhost