HttpClient execute keeps giving ConnectTimeoutException

ぐ巨炮叔叔 提交于 2019-11-28 00:19:14
Steven Xiao Xu Pen

The problem is the DefaultHttpClient. Are you using it asynchronously? Since the DefaultHttpClient is not thread-safe, using it in an asynchronous environment might cause a problem. I've had this problem before when my activity started multiple Http connection at the same time and i ended up changing it to use HttpURLConnection. You can refer to this site: http://www.vogella.de/articles/AndroidNetworking/article.html

I having the same issue.

Try using direct IP for your requests. I noticed that Android DNS lookups behave quite weird sometimes. I searched and found this : http://mailinglists.945824.n3.nabble.com/Android-and-reverse-DNS-lookup-issues-td3011461.html .

Dunno if it's relevant or not, i'm still trying to find a workaround. Maybe someone here can take a look and figure it out.

Check if you are able to connect using your development machine, Also check the load times. There is a very good chance your timeouts are way too small.

GregoryK

Had a similar issue, could be reproduced only when trying to connect using several devices simultaneously and the solution was:

Instance reboot solved problem with connections. (or just need to restart networking service)

(c) My server/instance admin

Also, there are people who experience similar issues and some other solutions worked for them, for instance:

  1. Disable tcp_timestamp
  2. Disable tcp_tw_reuse & tcp_tw_recycle
  3. Enabled vm save mode in Android manifest: android:vmSafeMode="true"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!