Fix for pull request #73, it's because 'The TcpListener.Stop method also closes the underlying Socket, and creates a new Socket for the TcpListener. If you set any properties on the underlying Socket prior to calling the Stop method, those properties will not carry over to the new Socket.'

This commit is contained in:
sta 2014-09-04 16:03:53 +09:00
parent bc4cb2033d
commit a1373347c6
2 changed files with 8 additions and 6 deletions

View File

@ -39,6 +39,9 @@ namespace Example2
// Not to remove inactive clients periodically // Not to remove inactive clients periodically
//wssv.KeepClean = false; //wssv.KeepClean = false;
// To resolve to wait for socket in TIME_WAIT state
//wssv.ReuseAddress = true;
// Adding WebSocket services // Adding WebSocket services
wssv.AddWebSocketService<Echo> ("/Echo"); wssv.AddWebSocketService<Echo> ("/Echo");
wssv.AddWebSocketService<Chat> ("/Chat"); wssv.AddWebSocketService<Chat> ("/Chat");

View File

@ -452,12 +452,7 @@ namespace WebSocketSharp.Server
return; return;
} }
if (value ^ _reuseAddress) { _reuseAddress = value;
_listener.Server.SetSocketOption (
SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, value);
_reuseAddress = value;
}
} }
} }
@ -779,6 +774,10 @@ namespace WebSocketSharp.Server
return; return;
} }
if (_reuseAddress)
_listener.Server.SetSocketOption (
SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
_services.Start (); _services.Start ();
_listener.Start (); _listener.Start ();
startReceiving (); startReceiving ();