且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

java.net.ConnectException:无法连接到/192.168.253.3(端口 2468):连接失败:ECONNREFUSED(连接被拒绝)

更新时间:2022-05-14 08:47:51

A connect failed: ECONNREFUSED (Connection denied) 很可能意味着在该端口和该 IP 地址上没有侦听任何内容.可能的解释包括:

A connect failed: ECONNREFUSED (Connection refused) most likely means that there is nothing listening on that port AND that IP address. Possible explanations include:

  • 服务已崩溃或尚未(成功!)启动,
  • 您的客户端正在尝试使用错误的 IP 地址或端口进行连接,
  • 您的客户端正在尝试使用解析为错误 IP 的 DNS 名称进行连接,或者
  • 服务器访问被代表服务器/服务拒绝"的防火墙阻止.这不太可能,因为通常的做法(现在)是让防火墙黑洞"所有不需要的连接尝试.
  • the service has crashed or hasn't been (successfully!) started,
  • your client is trying to connect using the wrong IP address or port,
  • your client is trying to connect using a DNS name that resolves to the wrong IP, or
  • server access is being blocked by a firewall that is "refusing" on the server/service's behalf. This is pretty unlikely given that normal practice (these days) is for firewalls to "blackhole" all unwanted connection attempts.

请注意,虽然您有一个名为 urls 的数组变量,但它不能包含真正的 URL.Socket 构造函数没有任何形式的真正 URL 的重载.事实上,如果你提供了一个像这样的字符串形式的 URL:

Note that while you have an array variable called urls, it cannot contain real URLs. There is no overload of the Socket constructor that takes a real URL in any form. Indeed, if you supplied a URL in string form like this:

 new Socket("http://example.com", 42)

结果将是一个不同的例外.同样,如果您尝试连接到无法路由到的网络上的 IP 地址(例如不同的 WiFi 网络"),那么您将收到不同的异常;例如找不到主机"、没有到主机的路由"或没有到网络的路由".

the result would be a different exception. Likewise, if you attempt to connect to an IP address on a network that you can't route to (e.g. "a different WiFi network"), then you will get a different exception; e.g. "host not found", "no route to host" or "no route to network".