Problem with nsurlconnection timeout - iphone

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...

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.

Increasing WS Promise timeout

I'm calling a REST ws that takes more time than 5 seconds and I'm getting a timeout for the Promise response. How can I increase this time above 5 seconds?
You can pass a Long to the get method of the promise that corresponds to the timeout of this method. For example:
promise.get(120000L);
would set a 2 minutes timeout for the get method.

HttpUrlConnection taking exactly 2 minutes for timeout

Whenever the URL is trying to load, it takes larger than the time set in the connection timeout, but setting the connection timeout to 20 seconds does not work it happens only after 2 minutes, and also whatever the time that is set in the connection time out, its taking exactly 2 minutes for the server to connection time out.
URL urlConnect = new URL(url.toString());
HttpURLConnection urlc = (HttpURLConnection) urlConnect.openConnection();
urlc.setDoInput(true);
urlc.setConnectTimeout(1000 * 20); // Timeout is in MILLI seconds
urlc.connect();
Or whether the 2 minutes is the default values for timeout? how to set the timeout to exactly 20 seconds. It doesnot have any redirect urls or anythings its a plain url. Why is it taking exactly 2 minutes for the connection to timeout?

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.

Is there any timeout period for NSData datawithcontentsofurl?

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.