How can i set a timeout for SSL sockets for a blocking read/write using the ThreadSafeClientConnectionManaget? I've found that losing network connectivity while reading or writing a 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);
I then use the client to perform a http put request with a file entity. If I turn on airplane mode in mid upload, wait 15-30 seconds and then turn off airplane mode the socket will be stuck in either a read or write and won't timeout for 15 mins.
Not to pivot away from your very legitimate question, but the blog post Android's HTTP Clients recommends using HttpURLConnection for new development. Have you considered switching APIs?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With