How to Close a Socket Left Open by a Killed Program

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

Assume your socket is named s... you need to set socket.SO_REUSEADDR on the server's socket before binding to an interface... this will allow you to immediately restart a TCP server...

s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((ADDR, PORT))

How to close sockets left open by a killed program?

According to;

https://superuser.com/questions/127863/manually-closing-a-port-from-commandline

Only an application can close the sockets it is using, after the applications process is killed, the sockets should be automatically freed within a couple of minutes. Are you being patient enough?

Socket remains open after program has closed (C++)

http://hea-www.harvard.edu/~fine/Tech/addrinuse.html should answer a lot of your questions. I tend to use SO_REUSEADDR to work around that problem.



Related Topics



Leave a reply



Submit