Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are default values for connection and socket timeouts in DefaultHttpClient on Android?

On Android 2.1/2.2 I use DefaultHttpClient found in Android SDK.

Apache says in their docs there are 2 timeouts:

  • CoreConnectionPNames.SO_TIMEOUT='http.socket.timeout': defines the socket timeout (SO_TIMEOUT) in milliseconds, which is the timeout for waiting for data or, put differently, a maximum period inactivity between two consecutive data packets). A timeout value of zero is interpreted as an infinite timeout. This parameter expects a value of type java.lang.Integer. If this parameter is not set, read operations will not time out (infinite timeout).

  • CoreConnectionPNames.CONNECTION_TIMEOUT='http.connection.timeout': determines the timeout in milliseconds until a connection is established. A timeout value of zero is interpreted as an infinite timeout. This parameter expects a value of type java.lang.Integer. If this parameter is not set, connect operations will not time out (infinite timeout).

I tried searching Android sources for default values for these 2 timeouts, but was unable to find. Does anyone know what are the default values for these timeouts? I'd like to get a link to sources where the values are set or an official doc on this (versus just to hear an opinion).

like image 590
Vit Khudenko Avatar asked Feb 10 '12 12:02

Vit Khudenko


People also ask

What is the default socket timeout?

The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period.

What is a good connection timeout?

Connect Timeout Meaning, in general, that you cannot contact the service. Setting a low connect timeout, like 2 seconds, might be useful to prevent your application (worker, job, etc.) to remain “blocked” for a long time, as the server probably has a problem.

What is socket connection timeout?

socket timeout — a maximum time of inactivity between two data packets when exchanging data with a server.

What is the default timeout for retrofit Android?

By default, Retrofit uses the following timeouts: Connection timeout: 10 seconds. Read timeout: 10 seconds.


1 Answers

Just try below below code section:

import android.net.http.AndroidHttpClient;
...
        AndroidHttpClient h = AndroidHttpClient.newInstance("My http client");
        // ...
        Log.d(TAG, "http.socket.timeout: " + h.getParams().getParameter("http.socket.timeout"));
        Log.d(TAG, "http.connection.timeout: " + h.getParams().getParameter("http.connection.timeout"));

It works on my device:

12-02 16:27:54.119 D/Exam(17121): http.socket.timeout: 60000
12-02 16:27:54.119 D/Exam(17121): http.connection.timeout: 60000
like image 68
lucky1928 Avatar answered Sep 23 '22 21:09

lucky1928