且构网

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

I/O 错误(套接字错误):[Errno 111] 连接被拒绝

更新时间:2021-08-08 20:08:38

使用像 Wireshark 这样的数据包嗅探器来看看会发生什么.您需要看到带有 SYN 标志的数据包传出、带有 SYN+ACK 标志的传入和带有 ACK 标志的传出.之后,该端口在本地被认为是开放的.

Use a packet sniffer like Wireshark to look at what happens. You need to see a SYN-flagged packet outgoing, a SYN+ACK-flagged incoming and then a ACK-flagged outgoing. After that, the port is considered open on the local side.

如果您只看到第一个数据包并且在等待几秒钟后出现错误消息,则另一方根本没有响应(例如:拔下电缆、服务器过载、错误引导的数据包被丢弃)并且您的本地网络堆栈中止连接尝试.如果您看到 RST 数据包,则主机实际上拒绝连接.如果您看到ICMP 端口无法访问"或主机无法访问的数据包,则防火墙或目标主机会通知您该端口实际上已关闭.

If you only see the first packet and the error message comes after several seconds of waiting, the other side is not answering at all (like in: unplugged cable, overloaded server, misguided packet was discarded) and your local network stack aborts the connection attempt. If you see RST packets, the host actually denies the connection. If you see "ICMP Port unreachable" or host unreachable packets, a firewall or the target host inform you of the port actually being closed.

当然,您不能期望服务始终可用(考虑您和数据之间的所有故障点),因此您应该稍后再试.

Of course you cannot expect the service to be available at all times (consider all the points of failure in between you and the data), so you should try again later.