What are default values for connection and socket

2019-04-04 03:42发布

问题:

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

回答1:

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


回答2:

Wouldn't you be able to get the default (or whatever values are set) using something like the following:

DefaultHttpClient h;
// ...
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's worth a shot if you really want to know what the default values are (as opposed to just setting the values yourself).