diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs index ee22f9ea..ff849add 100644 --- a/websocket-sharp/Server/WebSocketServer.cs +++ b/websocket-sharp/Server/WebSocketServer.cs @@ -71,6 +71,7 @@ namespace WebSocketSharp.Server private volatile ServerState _state; private object _sync; private Uri _uri; + private bool _reuseAddress; #endregion @@ -451,6 +452,39 @@ namespace WebSocketSharp.Server } } + /// + /// Gets or sets a value indicating whether the server is allowed to be bound to an address + /// that is already in use. + /// + /// + /// If you would like to resolve to wait for socket TIME_WAIT, you should set this + /// property to true. + /// + /// + /// true if the server is allowed to be bound to an address that is already in use; + /// otherwise, false. The default value is false. + /// + public bool ReuseAddress + { + get + { + return _reuseAddress; + } + + set + { + if (!canSet("ReuseAddress")) + return; + + if (value ^ _reuseAddress) + { + _listener.Server.SetSocketOption( + SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, value); + + _reuseAddress = value; + } + } + } #endregion #region Private Methods @@ -840,7 +874,6 @@ namespace WebSocketSharp.Server _state = ServerState.Stop; } - #endregion } }