How to get a specific socket and close it

前端 未结 3 1465
隐瞒了意图╮
隐瞒了意图╮ 2021-01-16 03:47

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

相关标签:
3条回答
  • 2021-01-16 04:20

    You could investigate SO_REUSEADDR.

    0 讨论(0)
  • 2021-01-16 04:31

    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.

    0 讨论(0)
  • 2021-01-16 04:34

    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.

    0 讨论(0)
提交回复
热议问题