How can I forcibly close a TcpListener

Posted by Nissim on Stack Overflow See other posts from Stack Overflow or by Nissim
Published on 2010-06-07T19:44:57Z Indexed on 2010/06/07 19:52 UTC
Read the original article Hit count: 203

Filed under:
|
|
|
|

I have a service which communicates through tcpListener. Problem is when the user restarts the service - an "Address already in use" exception is thrown, and the service cannot be started for a couple of minutes or so.

Is there's any way of telling the system to terminate the old connection so I can open a new one? (I can't just use random ports because there is no way for the service to notify the clients what is the port, so we must depend on a predefined port)

© Stack Overflow or respective owner

Related posts about c#

Related posts about sockets