I am using DefaultHttpClient for connection. What I would like to do is "keep checking if it's alive" and when timeed out, reconnect. How can I do that ? I tried that entity is not null the consumeContent. Is it not working for me.
            Asked
            
        
        
            Active
            
        
            Viewed 354 times
        
    0
            
            
        - 
                    A better approach might be to simply _assume_ it is alive and deal with it accordingly if it is not. – Aaron McIver Feb 17 '12 at 19:12
 - 
                    OK then how do deal with it when it's timed out. – user1143989 Feb 17 '12 at 19:14
 
1 Answers
0
            One way to handle this is to set a HttpRequestRetryHandler and deal with the retry accordingly.
client.setHttpRequestRetryHandler(retryHandler);
You can also adjust the timeout via the HttpParams as noted here which may suffice depending on your exact needs; however building in retry behavior is a good approach either way.
final HttpParams httpParameters = yourHttpClient.getParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, connectionTimeOutSec * 1000);
HttpConnectionParams.setSoTimeout        (httpParameters, socketTimeoutSec * 1000);
        Community
        
- 1
 - 1
 
        Aaron McIver
        
- 24,527
 - 5
 - 59
 - 88