How to set timeout for SSL sockets to block read / write using ThreadSafeClientConnectionManaget? I found that losing a network connection when reading or writing an SSL socket results in a 15-minute timeout on Android OS 2.2 and 2.3 devices.
I set the following timeouts on my HttpClient:
mParams = new BasicHttpParams(); HttpProtocolParams.setVersion(mParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(mParams, "UTF-8"); HttpProtocolParams.setUserAgent(mParams, USER_AGENT); HttpConnectionParams.setConnectionTimeout(mParams, TIME_OUT); HttpConnectionParams.setSoTimeout(mParams, TIME_OUT); ConnManagerParams.setTimeout(mParams, TIME_OUT); final SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme(HTTP_SCHEME, PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme(HTTPS_SCHEME, SSLSocketFactory.getSocketFactory(), 443)); final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(mParams, registry); mClient = new DefaultHttpClient(manager, mParams);
Then I use the client to execute the http put request with the file entity. If I turn on airplane mode in the middle of loading, wait 15-30 seconds, and then turn off airplane mode, the slot will get stuck in read or write mode and will not be timeout for 15 minutes.
Todd
source share