diff --git a/Example2/Program.cs b/Example2/Program.cs index bb6a86d6..b6c68975 100644 --- a/Example2/Program.cs +++ b/Example2/Program.cs @@ -39,6 +39,9 @@ namespace Example2 // Not to remove inactive clients periodically //wssv.KeepClean = false; + // To resolve to wait for socket in TIME_WAIT state + //wssv.ReuseAddress = true; + // Adding WebSocket services wssv.AddWebSocketService ("/Echo"); wssv.AddWebSocketService ("/Chat"); diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs index bec0a92a..c2f0fe2e 100644 --- a/websocket-sharp/Server/WebSocketServer.cs +++ b/websocket-sharp/Server/WebSocketServer.cs @@ -452,12 +452,7 @@ namespace WebSocketSharp.Server return; } - if (value ^ _reuseAddress) { - _listener.Server.SetSocketOption ( - SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, value); - - _reuseAddress = value; - } + _reuseAddress = value; } } @@ -779,6 +774,10 @@ namespace WebSocketSharp.Server return; } + if (_reuseAddress) + _listener.Server.SetSocketOption ( + SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); + _services.Start (); _listener.Start (); startReceiving ();