1

I use android-async-http in my project, and AsyncHttpClient static single instance, my code as follow step:

  1. HttpURLConnection http request;
  2. In first request success callback, use AsyncHttpClient to request another url;
  3. Get ConnectTimeoutException as follows:

06-28 18:35:36.440 18638-19939/com.zebra.carcloud.example W/System.err: cz.msebera.android.httpclient.conn.ConnectTimeoutException: Connect to daily.yuncar.zebred.com/139.196.2.83:7090 timed out 06-28 18:35:36.441 18638-19939/com.zebra.carcloud.example W/System.err: at cz.msebera.android.httpclient.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119) 06-28 18:35:36.441 18638-19939/com.zebra.carcloud.example W/System.err: at cz.msebera.android.httpclient.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:157) 06-28 18:35:36.441 18638-19939/com.zebra.carcloud.example W/System.err: at cz.msebera.android.httpclient.conn.scheme.SchemeSocketFactoryAdaptor.connectSocket(SchemeSocketFactoryAdaptor.java:65) 06-28 18:35:36.441 18638-19939/com.zebra.carcloud.example W/System.err: at cz.msebera.android.httpclient.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177) 06-28 18:35:36.441 18638-19939/com.zebra.carcloud.example W/System.err: at cz.msebera.android.httpclient.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:145) 06-28 18:35:36.442 18638-19939/com.zebra.carcloud.example W/System.err: at cz.msebera.android.httpclient.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:131) 06-28 18:35:36.442 18638-19939/com.zebra.carcloud.example W/System.err: at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611) 06-28 18:35:36.442 18638-19939/com.zebra.carcloud.example W/System.err: at cz.msebera.android.httpclient.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446) 06-28 18:35:36.442 18638-19939/com.zebra.carcloud.example W/System.err: at cz.msebera.android.httpclient.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:860) 06-28 18:35:36.442 18638-19939/com.zebra.carcloud.example W/System.err: at cz.msebera.android.httpclient.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) 06-28 18:35:36.442 18638-19939/com.zebra.carcloud.example W/System.err: at com.loopj.android.http.AsyncHttpRequest.makeRequest(AsyncHttpRequest.java:146) 06-28 18:35:36.443 18638-19939/com.zebra.carcloud.example W/System.err: at com.loopj.android.http.AsyncHttpRequest.makeRequestWithRetries(AsyncHttpRequest.java:177) 06-28 18:35:36.443 18638-19939/com.zebra.carcloud.example W/System.err: at com.loopj.android.http.AsyncHttpRequest.run(AsyncHttpRequest.java:106) 06-28 18:35:36.443 18638-19939/com.zebra.carcloud.example W/System.err: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423) 06-28 18:35:36.443 18638-19939/com.zebra.carcloud.example W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237) 06-28 18:35:36.443 18638-19939/com.zebra.carcloud.example W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 06-28 18:35:36.443 18638-19939/com.zebra.carcloud.example W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 06-28 18:35:36.444 18638-19939/com.zebra.carcloud.example W/System.err: at java.lang.Thread.run(Thread.java:818)

I google for a while but couldn't find the reason, someone meet same question with me:loopj issues 725, but I set AsyncHttpClient timeout to 30000(default 10000), and still get ConnectTimeoutException after 30 seconds.

Modify single instance to new AsyncHttpClient instance before second request, every thing will be OK. I don't know whether the HttpURLConnection operation effects the AsyncHttpClient or not.

Stephane Landelle
  • 6,990
  • 2
  • 23
  • 29
Brant
  • 221
  • 1
  • 3
  • 7
  • The library you are using uses the Apache HttpClient library, which is no longer supported by Android, for [good reason](https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#apache-http-client-removal). Android suggests to use the [`HttpURLConnection`](https://developer.android.com/reference/java/net/HttpURLConnection.html) class from the `java.net` package, but as @apelsoczi suggested, it may be easier with another library such as [Retrofit](http://square.github.io/retrofit/). – Bryan Jun 28 '16 at 14:30
  • I was facing similar issue but then figured out that I had network issues, causing connection timeout. I am using the same library in my android app and it is very well supported. Make sure you do not have any network issues and the server ULR is correct. – akshitmahajan Oct 08 '16 at 19:00

0 Answers0