diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs
index 99ff33c1..f7416358 100644
--- a/websocket-sharp/Server/WebSocketServer.cs
+++ b/websocket-sharp/Server/WebSocketServer.cs
@@ -84,22 +84,22 @@ namespace WebSocketSharp.Server
/// Initializes a new instance of the class.
///
///
- /// An instance initialized by this constructor listens for the incoming connection requests
- /// on port 80.
+ /// An instance initialized by this constructor listens for the incoming
+ /// connection requests on port 80.
///
public WebSocketServer ()
- : this (System.Net.IPAddress.Any, 80, false)
{
+ init (System.Net.IPAddress.Any, 80, false);
}
///
- /// Initializes a new instance of the class with the specified
- /// .
+ /// Initializes a new instance of the class with
+ /// the specified .
///
///
///
- /// An instance initialized by this constructor listens for the incoming connection requests
- /// on .
+ /// An instance initialized by this constructor listens for the incoming
+ /// connection requests on .
///
///
/// If is 443, that instance provides a secure connection.
@@ -109,37 +109,49 @@ namespace WebSocketSharp.Server
/// An that represents the port number on which to listen.
///
///
- /// isn't between 1 and 65535.
+ /// isn't between 1 and 65535 inclusive.
///
public WebSocketServer (int port)
- : this (System.Net.IPAddress.Any, port, port == 443)
{
+ if (!port.IsPortNumber ())
+ throw new ArgumentOutOfRangeException (
+ "port", "Not between 1 and 65535 inclusive: " + port);
+
+ init (System.Net.IPAddress.Any, port, port == 443);
}
///
- /// Initializes a new instance of the class with the specified
- /// WebSocket URL.
+ /// Initializes a new instance of the class with
+ /// the specified WebSocket URL.
///
///
///
- /// An instance initialized by this constructor listens for the incoming connection requests
- /// on the port in .
+ /// An instance initialized by this constructor listens for the incoming
+ /// connection requests on the port in .
///
///
- /// If doesn't include a port, either port 80 or 443 is used on which
- /// to listen. It's determined by the scheme (ws or wss) in .
+ /// If doesn't include a port, either port 80 or 443 is used on
+ /// which to listen. It's determined by the scheme (ws or wss) in .
/// (Port 80 if the scheme is ws.)
///
///
///
/// A that represents the WebSocket URL of the server.
///
- ///
- /// is invalid.
- ///
///
/// is .
///
+ ///
+ ///
+ /// is empty.
+ ///
+ ///
+ /// -or-
+ ///
+ ///
+ /// is invalid.
+ ///
+ ///
public WebSocketServer (string url)
{
if (url == null)
@@ -148,27 +160,26 @@ namespace WebSocketSharp.Server
if (url.Length == 0)
throw new ArgumentException ("An empty string.", "url");
+ Uri uri;
string msg;
- if (!tryCreateUri (url, out _uri, out msg))
+ if (!tryCreateUri (url, out uri, out msg))
throw new ArgumentException (msg, "url");
- _address = _uri.DnsSafeHost.ToIPAddress ();
- if (_address == null || !_address.IsLocal ())
+ var addr = uri.DnsSafeHost.ToIPAddress ();
+ if (!addr.IsLocal ())
throw new ArgumentException ("The host part isn't a local host name: " + url, "url");
- _port = _uri.Port;
- _secure = _uri.Scheme == "wss";
-
- init ();
+ _uri = uri;
+ init (addr, uri.Port, uri.Scheme == "wss");
}
///
- /// Initializes a new instance of the class with the specified
- /// and .
+ /// Initializes a new instance of the class with
+ /// the specified and .
///
///
- /// An instance initialized by this constructor listens for the incoming connection requests
- /// on .
+ /// An instance initialized by this constructor listens for the incoming
+ /// connection requests on .
///
///
/// An that represents the port number on which to listen.
@@ -181,7 +192,7 @@ namespace WebSocketSharp.Server
/// Pair of and is invalid.
///
///
- /// isn't between 1 and 65535.
+ /// isn't between 1 and 65535 inclusive.
///
public WebSocketServer (int port, bool secure)
: this (System.Net.IPAddress.Any, port, secure)
@@ -189,13 +200,13 @@ namespace WebSocketSharp.Server
}
///
- /// Initializes a new instance of the class with the specified
- /// and .
+ /// Initializes a new instance of the class with
+ /// the specified and .
///
///
///
- /// An instance initialized by this constructor listens for the incoming connection requests
- /// on .
+ /// An instance initialized by this constructor listens for the incoming
+ /// connection requests on .
///
///
/// If is 443, that instance provides a secure connection.
@@ -207,14 +218,14 @@ namespace WebSocketSharp.Server
///
/// An that represents the port number on which to listen.
///
- ///
- /// isn't a local IP address.
- ///
///
/// is .
///
+ ///
+ /// isn't a local IP address.
+ ///
///
- /// isn't between 1 and 65535.
+ /// isn't between 1 and 65535 inclusive.
///
public WebSocketServer (System.Net.IPAddress address, int port)
: this (address, port, port == 443)
@@ -222,12 +233,13 @@ namespace WebSocketSharp.Server
}
///
- /// Initializes a new instance of the class with the specified
- /// , , and .
+ /// Initializes a new instance of the class with
+ /// the specified , , and
+ /// .
///
///
- /// An instance initialized by this constructor listens for the incoming connection requests on
- /// .
+ /// An instance initialized by this constructor listens for the incoming
+ /// connection requests on .
///
///
/// A that represents the local IP address of the server.
@@ -272,12 +284,7 @@ namespace WebSocketSharp.Server
throw new ArgumentException (
String.Format ("An invalid pair of 'port' and 'secure': {0}, {1}", port, secure));
- _address = address;
- _port = port;
- _secure = secure;
- _uri = "/".ToUri ();
-
- init ();
+ init (address, port, secure);
}
#endregion
@@ -599,13 +606,16 @@ namespace WebSocketSharp.Server
: null;
}
- private void init ()
+ private void init (System.Net.IPAddress address, int port, bool secure)
{
+ _address = address;
+ _port = port;
+ _secure = secure;
+ _listener = new TcpListener (address, port);
+
_authSchemes = AuthenticationSchemes.Anonymous;
- _listener = new TcpListener (_address, _port);
_logger = new Logger ();
_services = new WebSocketServiceManager (_logger);
- _state = ServerState.Ready;
_sync = new object ();
}
@@ -617,7 +627,7 @@ namespace WebSocketSharp.Server
return;
}
- if (_uri.IsAbsoluteUri) {
+ if (_uri != null && _uri.IsAbsoluteUri) {
var actual = uri.DnsSafeHost;
var expected = _uri.DnsSafeHost;
if (Uri.CheckHostName (actual) == UriHostNameType.Dns &&