• 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: NSMutableURLRequest: Keeping the connection open
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableURLRequest: Keeping the connection open


  • Subject: Re: NSMutableURLRequest: Keeping the connection open
  • From: Jeremy Wyld <email@hidden>
  • Date: Wed, 30 Mar 2011 11:14:17 -0700

Also, be advised your application will have a battery impact as a result of holding the connection longer.  In cases, this can be an extreme impact.  On these devices, the latency could very well be a small cost compared to the usage your user gets.

jeremy

On Mar 30, 2011, at 11:06 AM, Mark Pauley wrote:

> NSURLConnection closes sockets after a relatively short period in order to allow the system to power the antenna down more quickly, thus saving battery life.
> The loader can't know when you are 'done' communicating to the server, and you can't really tell the loader because the details of tcp connections are completely hidden from your client code.
>
> If you absolutely must know about the underlying connections or if your app is hitting a pathologically bad case of socket management, feel free to drop down to CFHTTPReadStream, otherwise I would recommend that you not worry about the details of socket connections and just use NSURLConnection as is.
>
> If you do decide to use CFHTTPReadStream: make sure you don't close the stream until after you open the next stream.  This is how you can keep the underlying socket open.  Also be advised that you only get one socket per host / port pair going that route unless you want to get more tricky.
>
>
>
> On Mar 30, 2011, at 9:15 AM, Thomas Engelmeier wrote:
>
>> Hi,
>>
>> I´m trying to prevent NSMutableURLRequest / NSURLConnection from closing an connection after roughly  2 secs.
>> When within these two secs another request happens, the SSL connection stays open for another 2 secs.
>>
>> Is there a way to access the the underlying stream? Or pass through an keep alive parameter?
>> I'd try to avoid rewriting the networking code with custom CFStream based HTTP client implementation
>>
>> The connection code is something like
>>
>> 	NSMutableURLRequest* request =
>> [NSMutableURLRequest requestWithURL:fullURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData  timeoutInterval:90.]
>> 	[request setHTTPMethod:aMethod];
>> 	NSData* data = [self requestBodyForObject:anObject];
>> 	[request setHTTPBody:data];
>>
>> // code deleted
>>
>> 	if( !connection ) {
>> 		connection = [[NSURLConnection alloc] initWithRequest:aRequest delegate:self startImmediately:NO];
>> 		[connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
>> 		[connection start];
>>       }
>>
>> Things I tried:
>> - Playing a lot with an debug proxy (Charles), our code and SimpleURLConnections
>> - defer release of the NSURLConnection of the request until the next request gets created
>> - play with HTTP keep alive headers
>> - connect against different https:// websites
>>
>> TIA,
>> 	Thomas _______________________________________________
>> 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
>
> _______________________________________________
> 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

 _______________________________________________
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

  • Follow-Ups:
    • Re: NSMutableURLRequest: Keeping the connection open
      • From: Thomas Engelmeier <email@hidden>
References: 
 >NSMutableURLRequest: Keeping the connection open (From: Thomas Engelmeier <email@hidden>)
 >Re: NSMutableURLRequest: Keeping the connection open (From: Mark Pauley <email@hidden>)

  • Prev by Date: Re: NSMutableURLRequest: Keeping the connection open
  • Next by Date: Re: NSMutableURLRequest: Keeping the connection open
  • Previous by thread: Re: NSMutableURLRequest: Keeping the connection open
  • Next by thread: Re: NSMutableURLRequest: Keeping the connection open
  • Index(es):
    • Date
    • Thread