2

I'm using NSURLConnection to perform a series of HTTP requests to the same host asynchronously, i. e. with [initWithRequest:delegate:startImmediately:] and a delegate.

When connectionDidFinishLoading notification comes to the delegate, I release my connection object, then initialize and initiate another one, to the same host. Question - will the underlying socket be reused? The Connection:keep-alive server header is there, but I have no way of making sure that it's being respected. I mean, the first connection is not officially "done" yet when it issues the notification. Or is it?

EDIT: packet sniffing on Mac. PacketLogger ships along with hardware tools.

EDIT2: looks like it doesn't capture iOS simulator's activity.

Community
  • 1
  • 1
Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • I entered a bug report on this very same thing. There is no way to find out if a connection was held open or not. Note that flag you can set through NSURLConnection is only for HTTP/1.1. If you want to use the unofficial but widely used flag for 1.0, you must add it yourself to the header. – David H Nov 27 '13 at 16:51
  • The server is 1.1, and it supports keep-alives alright. It's the client implementation that I'm worried about. Is there a packet sniffer for Mac? – Seva Alekseyev Nov 27 '13 at 16:54
  • There is some packet capture utility in the utilities download - I just saw it when I got the Network Link Conditioner a few days ago. Go to the Downloads section and you will see the adjunct downloads posted in October. – David H Nov 27 '13 at 16:56
  • @SevaAlekseyev - Is there anyway to disable keep-alive in NSURLConnection ? – Durai Amuthan.H Mar 14 '15 at 18:24
  • Add a Connection:close header to the request. – Seva Alekseyev Mar 15 '15 at 00:42

1 Answers1

2

After some fiddling, got Wireshark to work on Mac. The TCP conversation is unbroken between requests - to me, this suggests keep-alive connections are working as advertised. iOS 7.0.3 on simulator.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281