How to get a specific socket and close it

前端 未结 3 1511
隐瞒了意图╮
隐瞒了意图╮ 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: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.

提交回复
热议问题