4

My questions is what is default timeout for requests made with DefaultHttpClient if I didn't specify it.

So if don't have code like this

HttpParams my_httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(my_httpParams, 3000);
HttpConnectionParams.setSoTimeout(my_httpParams, 1);

but just

HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setContentCharset(params,
                HTTP.DEFAULT_CONTENT_CHARSET);
ClientConnectionManager cm = new ThreadSafeClientConnManager(params,
                schemeRegistry);
SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", PlainSocketFactory
                .getSocketFactory(), 80));
return new DefaultHttpClient(cm, params);

How long will this httpClient wait for response from server?

Robert
  • 3,471
  • 3
  • 21
  • 24
  • 1
    As written in docs for HttpConnectionParams.getConnectionTimeout and HttpConnectionParams.getSoTimeout default value is 0 and it is interpreted as absence of timeout. Did I understand this correctly? – Robert Sep 04 '13 at 13:37
  • possible duplicate of [Timeout in DefaultHttpClient Class Android](http://stackoverflow.com/questions/7229189/timeout-in-defaulthttpclient-class-android) – rds Mar 11 '15 at 18:44

2 Answers2

4

As far as I know the connection timeout and socket timeout for the DefaultHttpClient are both null (or zero) by default, which means that the timeouts are not used and Android application will wait theoretically forever for both the connection and socket response to complete. Therefore, it is highly recommended that to provide new connection and socket timeouts when using the DefaultHttpClient.

Saifuddin Sarker
  • 853
  • 3
  • 8
  • 26
0

I did some snooping around in the source and found these two methods. So it looks like they default to 0.

/**
 * Obtains value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT}
 * parameter. If not set, defaults to <code>0</code>.
 *
 * @param params HTTP parameters.
 * @return connect timeout.
 */
public static int getConnectionTimeout(final HttpParams params) {
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    return params.getIntParameter
        (CoreConnectionPNames.CONNECTION_TIMEOUT, 0);
}

/**
 * Obtains value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter.
 * If not set, defaults to <code>0</code>.
 *
 * @param params HTTP parameters.
 * @return SO_TIMEOUT.
 */
public static int getSoTimeout(final HttpParams params) {
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    return params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0);
}
Joseph Helfert
  • 421
  • 3
  • 13