Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does an NSURLRequest time out?

The NSURLRequest class (iOS docs, OS X docs) in Cocoa has a timeoutInterval property. The docs state

If during a connection attempt the request remains idle for longer than the timeout interval, the request is considered to have timed out.

What does 'idle' mean, here? As best as I can tell, what this means in practice is that if I set a 30 second timeoutInterval and call a method that sends the NSURLRequest, then if the body of the HTTP response hasn't returned 30 seconds after sending the request, the request times out. But is that really what's going on?

A few things I can think of that might trigger the idleness timer to reset: receiving the HTTP headers, or receiving part of the body. But which (if either) matters in reality?

like image 517
Mark Amery Avatar asked Jul 31 '13 17:07

Mark Amery


1 Answers

No bytes received for 30 seconds would be the normal definition. You should be able to write a very simple HTTP server (there are sample projects all over) and run it on a private port, then connect to it to prove it to yourself.

To simulate timing out in your server, just add "40" or some constant to the byte you are promising the client, so the client will wait forever for 40 bytes extra bytes at the end that aren't ever coming.

like image 130
Wil Shipley Avatar answered Sep 28 '22 02:09

Wil Shipley