多个HTTP请求与iOS上的单个TCP连接 [英] Multiple HTTP requests vs a single TCP connection on iOS

查看:376
本文介绍了多个HTTP请求与iOS上的单个TCP连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用我控制的基于Web的API的iPhone应用程序。连接到一个不断开放的TCP端口并通过TCP API发出请求,或者为我想要获取的所有数据发出新的HTTP请求会更快还是更有效?

I am developing an iPhone app that uses a web based API that I control. Would it be faster or more efficient to connect to a constantly open TCP port and make requests via the TCP API, or make a new HTTP request for all the data that I want to fetch?

我在想,差异可以忽略不计,但我可能错了。

I am imagining that the different would be negligible, but I could be wrong.

每次加载新视图时都会获取新数据,所以请求可以相当频繁地发生。

New data is fetched pretty much every time a new view is loaded, so requests can happen fairly frequently.

推荐答案

我认为差别很小。

值得注意的是NSURLConnection默认支持HTTP Keep Alive连接,因此您可以直接使用HTTP并确保您的服务器允许客户端保持连接活着。

It is also worth noting that NSURLConnection supports the HTTP Keep Alive connections by default, so you could go straight HTTP and make sure your server is allowing the client to keep the connection alive.

这篇关于多个HTTP请求与iOS上的单个TCP连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆