简体   繁体   English

HttpClient中的“拒绝连接”异常和超时之间的区别

[英]Difference between a “Connection Refused” exception and a timeout in HttpClient

I'm trying to determine whether a device on a network is running a web server or not using Java. 我正在尝试确定网络上的设备是否正在运行Web服务器或不使用Java。 To do this I'm using Apache's HttpClient. 为此,我使用的是Apache的HttpClient。 I send a request and if the device runs a web server I get a response - pretty simple. 我发送一个请求,如果设备运行Web服务器,我会得到响应-非常简单。

However, if a web server is not running then I've observed 2 things happen: 但是,如果Web服务器未运行,那么我观察到发生了两件事:

  • The request will be ignored and a timeout will occur 该请求将被忽略,并发生超时
  • An exception will be thrown. 将引发异常。 In particular, it will look like this: 特别是,它看起来像这样:

    org.apache.http.conn.HttpHostConnectException: Connect to 192.168.12.133:80 [/192.168.12.133] failed: Connection refused: connect org.apache.http.conn.HttpHostConnectException:连接到192.168.12.133:80 [/192.168.12.133]失败:连接被拒绝:connect

Is there anything that can be inferred about the device that I'm trying to connect to when I receive the "Connection refused" exception vs. getting no response at all? 当我收到“拒绝连接”异常与完全没有响应时,是否可以推断出我要连接的设备的任何信息?

Edit: 编辑:

Just to clarify: What I'm doing is running this against DEVICES on a local network. 只是要澄清一下:我正在做的是针对本地网络上的设备运行此操作。 That means NAS boxes, routers, Windows computers, iPads, etc. Some will have embedded web servers, others will not. 这意味着NAS盒,路由器,Windows计算机,iPad等。有些将带有嵌入式Web服务器,而有些则没有。 Most will not have firewalls. 大多数将没有防火墙。

I also know with 100% certainty that the device is up and running. 我还以100%的把握知道设备已启动并正在运行。

You cannot infer anything with 100% certainty, but: 您无法100%确定地推断任何内容,但是:

  • Connection timeout probably means either that the host / port is firewalled, OR the host is "off". 连接超时可能意味着主机/端口已防火墙,或者主机“关闭”。
  • Connection refused probably means that the host is not running any service on the port you are trying to connect to. 连接被拒绝可能意味着主机在您尝试连接的端口上没有运行任何服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 握手异常和连接拒绝异常之间的区别 - Difference between Handshake exception and Connection Refused exception Apache HTTPClient 给出连接被拒绝的异常 - Apache HTTPClient giving connection refused exception WebClient请求timeout()和HttpClient超时的区别 - Difference between timeout() in WebClient request and the timeout in HttpClient Mongo db超时异常,表示连接被拒绝 - Mongo db timeout exception saying connection refused apache HttpClient API中的setConnectionTimeout,setSoTimeout和“http.connection-manager.timeout”之间有什么区别 - What is the difference between the setConnectionTimeout , setSoTimeout and “http.connection-manager.timeout” in apache HttpClient API HttpClient MultipartRequest 连接被拒绝 - HttpClient MultipartRequest Connection Refused Java RMI Connect异常:连接拒绝主机/超时 - Java RMI Connect Exception: Connection refused to host / timeout HttpClient和连接超时 - HttpClient and Connection Timeout 套接字的连接超时和读取超时有什么区别? - What is the difference between connection and read timeout for sockets? Web服务连接超时和请求超时之间的差异 - Difference between web service connection timeout and request timeout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM