Is there any timeout period for NSData datawithcontentsofurl? - iphone

Is there any timeout period for NSData datawithcontentsofurl?

dataWithContentsOfURL may have an internal timeout but you want to use NSURLConnection instead, which allows for asynchronous communication. It also lets you specify a timeout interval.

Related

URLRequest timeoutInterval for entire call

Documentation states, that timeoutInterval for URLRequest is being measured not only from the start of the request, but anytime an event like new data is received occurs, time idle is being counted from 0.
Quote from documentation:
Hence, when an instance of load activity occurs (e.g. bytes are received from the network for a request), the idle interval for a request is reset to 0.
I wanted to ask if there is some other mechanism that doesn't restart when such event occurs, but simply gives a time from the beginning to the end, and if it takes longer then request is invalidated. I know that this can be easily achieved using dispatchAfter, just wanted to make sure there is no existing mechanism for this, so that I can use it.

maximum number if requests per TCP connection

I am acting as server which receives multiple requests from client in socket and handles in a thread.
Should i set any parameter in TCP level to set maximum number of requests a connection can handle simultaneously?
because in my server side ,if processing the request is slow i observe that other requests are queued up (client says request has been sent but i receive it late)
Kindly guide me
If it takes a long time to do the work and you want to handle multiple connections simultaneously, you have to change how you do things.
If you are actively using a lot of CPU during processing a long request, you'll need multiple threads. That's the only way to actually get more CPU time / second -- assuming you have multiple cores available.
If you are waiting on things like file IO, then you can instead use asynchronous processing to handle the requests on a single thread, but just handle a little piece at a time.
Setting a maximum number of TCP connections won't help you handle more processes more quickly. It will just reject connections and not even allow a first-come first-served type of behavior - it will just be random if a specific client ever gets through or not.

Maximum timeOut for NSMutableRequest & NSURLConnection

What is the maximum timeout interval I can use in my application. I m using following method.
(id)initWithURL:(NSURL *)URL cachePolicy:(NSURLRequestCachePolicy)cachePolicy timeoutInterval:(NSTimeInterval)timeoutInterval;
I m using GET Method.
Thanks
NSTimeInterval data type is typedef of double data type, so the maximum time out value supported is the value that is maximum for double data type.
I think you should take into account that HTTP uses TCP. TCP connections are not controlled only by your application, there are also many routers and firewalls in between your application and the server.
I took a look into a typical firewall documentation just to see what is the default timeout for TCP connections.
For CISCO it is one hour.
http://www.cisco.com/c/en/us/td/docs/security/asa/asa91/configuration/firewall/asa_91_firewall_config/conns_connlimits.html#42354
So maybe you should consider this information when deciding on maximum connection timeout.
Also see section 5.5 here : https://www.rfc-editor.org/rfc/rfc6202
They claim that the best practice is 30 seconds.

NSURLRequest setTimeoutInterval does not work as expected

I have kept NSURLRequest timeout interval 30sec. And I have also configured the auto retry 3 times for request. So if any problem comes in request then total time should be 120 seconds (i.e. 2 mins).
But When i have kept Debug point on my server and if i request to server then my time out period is getting 3 minutes.
Can I configure this timeout??? Or it should work??
Is this default timeout interval Once request is made to Server??
Please note that 30 seconds times 3 is 90 seconds, or one and a half minutes, not 2 minutes.
As for the timeout problem, try to init your NSURLRequest with initWithURL:cachePolicy:timeoutInterval:. Make sure to check the status of your NSURLConnection delegate methods, especially in connection:didFailWithError:.
Also, maybe you should explain how you measure the time out period on the server.

Problem with nsurlconnection timeout

I've got a wierd problem with NSURLConnection. I've set the connection time out of 20 seconds like this.
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
NSURLConnection *con= [[NSURLConnection alloc] initWithRequest:request delegate:self];
I'm implementing the delegate methods for the NSURLConnection as well.
Now when I ran the app, the connection did not time out after 20 seconds but after 2-3 minutes it gave error for 'No internet connection'. Isn't it supposed to give a timeout error after 20 seconds?
The discussion for timeoutInterval says that it starts (is set to 0) when a process of load activity occurs:
The timeout interval specifies the
limit on the idle
interval alloted to a request in the process of loading. The "idle
interval" is defined as the period of time that has passed since the
last instance of load activity occurred for a request that is in the
process of loading. Hence, when an instance of load activity occurs
(e.g. bytes are received from the network for a request), the idle
interval for a request is reset to 0. If the idle interval ever
becomes greater than or equal to the timeout interval, the request
is considered to have timed out. This timeout interval is measured
in seconds.
No internet connection is an error. So probably the timeout will actually occur in 20 seconds (set time) if it gets a connection but takes more time to load...