获取"SocketException:没有路由到主机"而不是预期的"SocketTimeoutException" [英] Get "SocketException: No route to host" instead of the expected "SocketTimeoutException"

查看:132
本文介绍了获取"SocketException:没有路由到主机"而不是预期的"SocketTimeoutException"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用DefaultHttpClient来满足几个要求.在缺少enternet的情况下,我仅在第一次下载时得到SocketTimeoutException,而在以后的下载中我得到java.net.SocketException: No route to host.为什么会这样?对于每个请求,我都使用新的httpClient.我需要为每个请求获取SocketTimeoutException,因为我应该保持两次下载尝试之间的超时延迟.

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.

推荐答案

查看此答案:

Android HttpUrlConnection HttpPost收到SocketException:无路由托管

Android应用-Java.Net.SocketException:无路由托管

此处一些说明:

您的192.168.1.114地址是动态分配的DHCP地址 您的路由器连接到PC.结果,它对仿真器可见.

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.

但是,取决于您的WiFi设置方式,Android可能会安装在 不同的路由器/子网,看不到192.168.1.114.你可以检查一下 在Android的地址栏中输入192.168.1.114 浏览器.

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.

如果192.168.1.114对您的Android不可见,则您必须 更改路由器上的路由规则以使其可见,或者 为此添加一个DNS查找.

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.

这篇关于获取"SocketException:没有路由到主机"而不是预期的"SocketTimeoutException"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆