How to "unbind" a socket programmatically?
Posted
by
ryan1894
on Stack Overflow
See other posts from Stack Overflow
or by ryan1894
Published on 2011-01-07T06:26:30Z
Indexed on
2011/01/07
6:53 UTC
Read the original article
Hit count: 249
1) The socket doesn't seem to unbind from the LocalEndPoint until the process ends.
2) I have tried the solutions from the other question, and also tried waiting a minute - to no avail.
3) At the moment I have tried the below to get rid of the socket and its connections:
public static void killUser(User victim)
{
LingerOption lo = new LingerOption(false, 0);
victim.connectedSocket.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.Linger, lo);
victim.connectedSocket.Shutdown(SocketShutdown.Both);
victim.connectedSocket.Disconnect(true);
victim.connectedSocket.Close();
clients.RemoveAt(victim.ID);
}
4) After a bit of googling, I can't seem to be able to unbind a port, thus if I have a sufficient amount of connecting clients, I will eventually run out of ports to listen on.
© Stack Overflow or respective owner