How to close a socket left open by a killed program?

后端 未结 3 1849
执念已碎
执念已碎 2020-12-01 03:33

I have a Python application which opens a simple TCP socket to communicate with another Python application on a separate host. Sometimes the program will either error or I w

3条回答
  •  被撕碎了的回忆
    2020-12-01 04:13

    You are confusing sockets, connections, and ports. Sockets are endpoints of connections, which in turn are 5-tuples {protocol, local-ip, local-port, remote-ip, remote-port}. The killed program's socket has been closed by the OS, and ditto the connection. The only relic of the connection is the peer's socket and the corresponding port at the peer host. So what you should really be asking about is how to reuse the local port. To which the answer is SO_REUSEADDR as per the other answers.

提交回复
热议问题