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

后端 未结 3 1850
执念已碎
执念已碎 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:02

    You might want to try using Twisted for your networking. Mike gave the correct low-level answer, SO_REUSEADDR, but he didn't mention that this isn't a very good option to set on Windows. This is the sort of thing that Twisted takes care of for you automatically. There are many, many other examples of this kind of boring low-level detail that you have to pay attention to when using the socket module directly but which you can forget about if you use a higher level library like Twisted.

提交回复
热议问题