线程“main”中的异常java.net.NoRouteToHostException:没有到主机的路由
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34217406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exception in thread "main" java.net.NoRouteToHostException: No route to host
提问by syed jameer
I don't know what is happening. Code is executing for 8-16 hours and then stops the execution of the program. Why? Can any one help on this?
我不知道发生了什么。代码执行 8-16 小时,然后停止执行程序。为什么?任何人都可以对此提供帮助吗?
Exception in thread "main" java.net.NoRouteToHostException: No route to host
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:123)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:133)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:108)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:554)
at example.producer.Spout6.main(Spout6.java:79)
回答by Ruchir Baronia
Could be a firewall... Or something like internet...Or too many ports...Here are the details:
可能是防火墙......或者像互联网......或者太多端口......这里是详细信息:
Signals that an error occurred while attempting to connect a socket to a remote address and port. Typically, the remote host cannot be reached because of an intervening firewall, or if an intermediate router is down.
尝试将套接字连接到远程地址和端口时发生错误的信号。通常,由于防火墙的介入或中间路由器关闭,无法访问远程主机。
Java docs
Java 文档
Also, you may be running out of available ports:
此外,您可能会耗尽可用端口:
Another important ramification of the ephemeral port range is that it limits the maximum number of connections from one machine to a specific service on a remote machine! The TCP/IP protocol uses the connection's 4-tuple to distinguish between connections, so if the ephemeral port range is only 4000 ports wide, that means that there can only be 4000 unique connections from a client machine to a remote service at one time. (http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html)
临时端口范围的另一个重要后果是它限制了从一台机器到远程机器上特定服务的最大连接数!TCP/IP 协议使用连接的 4 元组来区分连接,因此如果临时端口范围只有 4000 个端口宽,这意味着一次只能有 4000 个从客户端计算机到远程服务的唯一连接。( http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html)
Do this to get available ports to check:
执行此操作以获取要检查的可用端口:
$ cat /proc/sys/net/ipv4/ip_local_port_range
32768 61000
Note:
笔记:
It's certainly not a problem with the code, instead, try to keepa good connection by changing firewall settings, or getting stronger connection. Also, check the available ports by doing what I told you above.
这当然不是代码的问题,相反,请尝试通过更改防火墙设置或增强连接来保持良好的连接。另外,通过执行我上面告诉您的操作来检查可用端口。
回答by Stephen C
The exception typically indicates a network routing problem of some kind. This may be the result of a problem with the network configuration in you LAN or WAN, or it may be a result of a network link or switch outage. It can even be cause by failure of the host that you are trying to talk to.
异常通常表示某种网络路由问题。这可能是 LAN 或 WAN 中的网络配置出现问题的结果,也可能是网络链接或交换机中断的结果。它甚至可能是由您尝试与之交谈的主机故障引起的。
IMO, it is unlikely to be a network firewall issue, though that is also possible. (Normally a firewall will simply discard packets to block traffic, and that is most likely to result in connection timeouts. However, a firewall couldrespond with an Destination Unreachable packet that would result in this exception.)
IMO,这不太可能是网络防火墙问题,尽管这也是可能的。(通常,防火墙会简单地丢弃数据包以阻止流量,这很可能会导致连接超时。但是,防火墙可能会响应会导致此异常的 Destination Unreachable 数据包。)
回答by PANDURANG BHADANGE
It could be the issue with firewall
可能是防火墙的问题
If you are using Linux then follow steps:
如果您使用的是 Linux,请按照以下步骤操作:
Stop the firewall: > service iptables stop
停止防火墙:> service iptables stop
allow the port you want to connect on the host: > ufw allow [port_number]
允许你想在主机上连接的端口:> ufw allow [port_number]