Get “SocketException: No route to host” instead of the expected “SocketTimeoutException”

风流意气都作罢 提交于 2020-01-16 19:27:52

问题


I use the DefaultHttpClient to fulfill several downlaods. In the case when the enternet is absent I get SocketTimeoutException only for my first download, and for the next downloads I get java.net.SocketException: No route to host.Why does it occur? I use new httpClient for each request. I need to get SocketTimeoutException for each request, because I should keep the timeout delay between downloads attempts.


回答1:


Checkout this answers:

Android HttpUrlConnection HttpPost receive a SocketException: no route to host

Android App - Java.Net.SocketException: No route to host

And here some explanation :

Your 192.168.1.114 address is a DHCP address (dynamically) assigned by your router to your PC. As a result it is visible to the emulator.

But depending on how your WiFi is set up, the Android is probably on a different router / subnet and can't see 192.168.1.114. You could check that by typing 192.168.1.114 into the address bar of the Android browser.

If 192.168.1.114 is not visible to your Android, then you will have to either change the routing rules on your router to make it visible, or add a DNS lookup for it.



来源:https://stackoverflow.com/questions/16922907/get-socketexception-no-route-to-host-instead-of-the-expected-sockettimeoutex

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