• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Overlapping requests on multiple persistent connections?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Overlapping requests on multiple persistent connections?


  • Subject: Re: Overlapping requests on multiple persistent connections?
  • From: Michael Bernardo <email@hidden>
  • Date: Sat, 29 Nov 2008 10:00:25 -0500


On Nov 28, 2008, at 4:41 PM, Jens Alfke wrote:


On Nov 28, 2008, at 7:58 AM, Michael Bernardo wrote:

I've followed the model used by sample code at "/Developer/Examples/ Networking/Get Example" to get a single persistent connection working. I can verify that with single, serial requests, the connection is re-used.

This is a really old sample that predates the higher-level networking classes in Foundation. It still works, but these days if you want to use HTTP, you should almost certainly start with NSURLRequest / NSURLConnection, which do all the work for you, including managing multiple connections. These are the same classes that Safari uses.


The trouble starts when I try to send simultaneous overlapping requests. It seems that CFNetwork only creates a single underlying network connection, no matter how many simultaneous requests are outstanding.

Well, the code you're using manages the connections directly. A CFStream corresponds directly to a single TCP socket, and this sample code only creates one of them. If you wanted to change it to open multiple connections, you'd have to create multiple CFStreams, probably by creating multiple GetExampleDelegate objects.

Sorry, I should have been more clear. When I said I was sending "simultaneous overlapping requests", I mean to imply I was doing exactly this. If I create N CFReadStreams with the 'kCFStreamPropertyHTTPAttemptPersistentConnection' property enabled, to the same URL, with different request bodies, I only ever see 1 connection.


But I strongly recommend you stop using this code and use NSURLConnection instead. There is a lot of complexity to HTTP that this example doesn't get into, which you'd have to implement yourself — things like SSL support, pipelining, caching, GZIP compression…

I appreciate your opinion on this Jens. I'm aware of the Foundation classes and their associated benefits. All I can say is that my choice of API was not entirely arbitrary. :)


So, the question still remains - is there any way to do parallel requests with persistent connections?

-M _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Overlapping requests on multiple persistent connections? (From: Michael Bernardo <email@hidden>)
 >Re: Overlapping requests on multiple persistent connections? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Overlapping requests on multiple persistent connections?
  • Next by Date: Re: Overlapping requests on multiple persistent connections?
  • Previous by thread: Re: Overlapping requests on multiple persistent connections?
  • Next by thread: Re: Overlapping requests on multiple persistent connections?
  • Index(es):
    • Date
    • Thread