获取“SocketException: No route to host";而不是预期的“SocketTimeoutException" [英] Get "SocketException: No route to host" instead of the expected "SocketTimeoutException"

查看:19
本文介绍了获取“SocketException: No route to host";而不是预期的“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: no route主持

Android 应用程序 - Java.Net.SocketException:无路由主持

还有这里一些解释:

您的 192.168.1.114 地址是 DHCP 地址(动态)分配的你的路由器到你的电脑.因此,它对模拟器是可见的.

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: No route to host";而不是预期的“SocketTimeoutException"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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