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)?
-
do you mean NSURLConnection. It does asynchronous requests so I wouldn't worry about the performance costs. I wouldn't say it's memory footprint would be too bad but you could always check it with the 'allocations' instrument. – Remover Aug 23 '10 at 22:50
-
I'm wondering how **TCP Connection Establishment** http://ntrg.cs.tcd.ie/undergrad/4ba2/transport/5.pc.08.html is working on slow 3G/edge connection and will be there any advantages of using one connection vs a few connections – Dmytro Aug 27 '10 at 08:52
3 Answers
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.

- 3,339
- 5
- 39
- 60
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 :)

- 171
- 1
- 7
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.

- 2,522
- 5
- 27
- 36