From a1373347c6812786700697eab955b91a6904c621 Mon Sep 17 00:00:00 2001 From: sta Date: Thu, 4 Sep 2014 16:03:53 +0900 Subject: [PATCH] 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.' --- Example2/Program.cs | 3 +++ websocket-sharp/Server/WebSocketServer.cs | 11 +++++------ 2 files changed, 8 insertions(+), 6 deletions(-) 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 ();