Cost of creating a new NSConnection on iPhone
Does anybody know how expensive a tcp connec开发者_如何转开发tion 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)?
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/
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 :)
I have performed the following test. I've started a simple web server which is able to handle only two types of requests:
- return an image by number (8 images in total)
- return all images packed to one file
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.
精彩评论