0

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.

kosa
  • 65,990
  • 13
  • 130
  • 167
user1143989
  • 163
  • 1
  • 3
  • 18

1 Answers1

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