I am working on an Android application that requires using HttpClient to upload a file from an Android device to a web server. The download file can be up to 1 GB in size, so timeouts can occur if the device loses connection during the download. The strange thing is that the timeout that I set for the socket does not seem to have any effect. The application will just freeze when I lose the connection, instead of raising a SocketTimeoutException.
I tried using:
HttpConnectionParams.setConnectionTimeout(params, CrashLogParams.TIMEOUT); HttpConnectionParams.setSoTimeout(params, CrashLogParams.TIMEOUT);
but this only worked for the connection timeout, not the socket timeout. I also tried:
HttpParams p = httpclient.getParams(); p.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); p.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);
The reason I know that the connection timeout is due to the fact that I get an exception for the connection timeout after execution
httpclient.execute(httppost);
An application appears to hang when the connection is lost during the download, but after the application has successfully connected to the server.
To test my application, I disconnected the network at different times to see how the application would react. If I disconnect the network before sending the request, I get a connection error, and my application can gracefully process it, but if I disconnect it while the application is loading, it freezes. Of course, I am doing all these requests through AsyncTasks, so the main UI thread is not crashing. I am just wondering if there is another way to make sure the socket will time out without receiving any data, or if I missed something here. I read a lot of blogs and posts, but most of them just suggest using SO_TIMEOUT, which doesn't work for me.
sotimeout does not work in multi-page HTTP message on Android 2.1