How to "untie" a socket programmatically?

1) The socket does not seem to be untied from LocalEndPoint until the process is complete.
2) I tried the solutions from another question, and also tried to wait a minute - to no avail.
3) At the moment, I tried the following 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 small number of searches, I can’t disconnect the port, so if I have enough connecting clients, in the end I will not have ports to listen to.

+3
source share
1 answer

I suspect you are mixing the sockets of connected clients with your server.

- , . , , (, ) .

" ", / .

,

"" , .Bind(EndPoint), .Listen(). , / "" .

"" , , "" . . , , . :

  • Shutdown

, .

+7

Source: https://habr.com/ru/post/1784021/


All Articles