I want to close a socket so I can reopen one on the same port but I do not have a handle on that socket.
How can I get the socket that is listening on localhost:873
You could investigate SO_REUSEADDR.
Only that process that owns the socket can close it, so all you could try is ending the process that owns the socket.
From the command line you can find the Process ID of the process using a particular socket using the -o
option to netstat
. For example:
netstat -noa | findstr LISTENING
I don't know how you do this programmatically in .NET though.
Without a kernel driver this is not possible. It is not legal in Windows to grab a socket handle in another process and close it proactively.