在 iPhone 上创建新 NSConnection 的成本
有人知道 iPhone 上的 TCP 连接有多贵吗? 例如,如果我必须从 Web 服务器下载 8-10 个小文件 (2-6 kB),那么创建 8-10 个 NSConnection 请求是否有意义,或者最好向一次下载8-10个文件(假设服务器支持此类请求)?
Does anybody know how expensive a tcp connection is on iPhone?
For example, if I have to download 8-10 small files (2-6 kB) from a web server does it make sense to create 8-10 NSConnection requests or would be better to make one request to download 8-10 files at once (supposing that server supports such kind of requests)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不确定该操作有多昂贵......
但就我个人而言,我建议使用 ASIHTTP。这是一个包装类,旨在出色地处理此类情况。它甚至有一个队列,可以将所有 API 调用排队,然后在单独的线程中异步触发,甚至监视每个调用的进度。
http://allseeing-i.com/ASIHTTPRequest/
Not to sure about how expensive the operation is ...
Personally though, I would recommend using ASIHTTP. This is a wrapper class designed for handling situations like this marvelously. It even has a queue which can queue up all your API calls, fire then asynchronously in separate threads and even monitor the progress of each.
http://allseeing-i.com/ASIHTTPRequest/
如果您正在谈论 HTTP 并且服务器支持 HTTP keep-alive 我更喜欢使用一个连接对象。
无论如何,您可以测试这两种解决方案并让我们知道结果:)
If you are talking about HTTP and server supports HTTP keep-alive I'd prefer to use one connection object.
Anyway you can test both solutions and let us know the results :)
我进行了以下测试。我启动了一个简单的 Web 服务器,它只能处理两种类型的请求:
然后我编写了简单的 iPhone 应用程序,该应用程序请求 8 个图像 -每个请求一张图像,每个请求 8 个图像作为一个文件。
结果对我来说非常出乎意料,因为当我将所有图像作为一个文件请求时,一张图像的平均时间比单独请求时快 5-7 倍。
I have performed the following test. I've started a simple web server which is able to handle only two types of requests:
Then I've written simple iPhone application which requested 8 images - one image per request and 8 images per request as one file.
The results were quite unexpected for me because average time for one image when I requested all images as one file was 5-7 times faster than when requested separately.