http connection timeout issues

前端 未结 10 1501
感情败类
感情败类 2020-12-13 20:54

I\'m running into an issue when i try to use the HttpClient connecting to a url. The http connection is taking a longer time to timeout, even after i set a connection timeoo

相关标签:
10条回答
  • 2020-12-13 21:18

    The problem might be in the Apache HTTP Client. See HTTPCLIENT-1098. Fixed in 4.1.2.

    The timeout exception tries to reverse DNS the IP, for logging purposes. This takes an additional time until the exception is actually fired.

    0 讨论(0)
  • 2020-12-13 21:19

    You could manage the timeouts yourself, this way you can be confident that no matter what state the connection gets in, unless you receive an acceptable response, that your timeout will fire and the http request will be aborted.

    0 讨论(0)
  • 2020-12-13 21:24

    Although I haven't seen this on the Android platform, I've seen similar things on other platforms and the solution in these cases is to manage the timeout yourself. Kick off another thread (the timeout thread) when your make your request. The timeout thread counts down the requisite time. If the timeout expires before you receive any data, the timeout thread cancels the original request and you retry with a new request. Harder to code, but at least you know it will work.

    0 讨论(0)
  • 2020-12-13 21:29

    Well, if you idle/multitask to another application, then your thread that is running might be stopped and destroyed. Maybe you should put the connection code inside a Service instead?:

    http://developer.android.com/reference/android/os/AsyncTask.html http://developer.android.com/reference/android/app/IntentService.html

    0 讨论(0)
提交回复
热议问题