I had a strange problem: I had never done this before, here is the server code (in this case, the firefox client), how I create it:
_Socket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
_Socket.Bind( new IPEndPoint( Settings.IP, Settings.Port ) );
_Socket.Listen( 1000 );
_Socket.Blocking = false;
The way I accept the connection:
while( _IsWorking )
{
if( listener.Socket.Poll( -1, SelectMode.SelectRead ) )
{
Socket clientSocket = listener.Socket.Accept();
clientSocket.Blocking = false;
clientSocket.SetSocketOption( SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true );
}
}
So, I expect it to hang on listener.Socket.Poll until a new connection appears, but after the first start it hangs in the poll forever. I tried to interrogate it constantly with a shorter delay, say 10 microseconds, then it never goes to SelectMode.SelectRead. I think this may be due to the reuse of the client socket? Perhaps I am not closing the client socket and the client (firefox) decides to use the old socket?
I will disconnect the client socket as follows:
Context.Socket.Shutdown( SocketShutdown.Both );
Context.Socket.Close();
What can cause this problem?
source
share