diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index 2ca1a666..67b93795 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -1538,8 +1538,13 @@ namespace WebSocketSharp var port = uri.Port; if (port > 0) { - if ((scheme == "ws" && port == 443) || - (scheme == "wss" && port == 80)) + if (port > 65535) + { + message = "Invalid port number: " + port; + return false; + } + + if ((scheme == "ws" && port == 443) || (scheme == "wss" && port == 80)) { message = String.Format ("Invalid pair of scheme and port: {0}, {1}", scheme, port); return false; diff --git a/websocket-sharp/Server/HttpServer.cs b/websocket-sharp/Server/HttpServer.cs index dce9a5e7..d9f0c200 100644 --- a/websocket-sharp/Server/HttpServer.cs +++ b/websocket-sharp/Server/HttpServer.cs @@ -106,12 +106,13 @@ namespace WebSocketSharp.Server if (!port.IsPortNumber ()) throw new ArgumentOutOfRangeException ("port", "Invalid port number: " + port); - if (port == 80 && secure || port == 443 && !secure) + if ((port == 80 && secure) || (port == 443 && !secure)) throw new ArgumentException (String.Format ( "Invalid pair of 'port' and 'secure': {0}, {1}", port, secure)); _port = port; _secure = secure; + init (); } diff --git a/websocket-sharp/Server/WebSocketServerBase.cs b/websocket-sharp/Server/WebSocketServerBase.cs index f1bea7a5..7b84faee 100644 --- a/websocket-sharp/Server/WebSocketServerBase.cs +++ b/websocket-sharp/Server/WebSocketServerBase.cs @@ -135,6 +135,9 @@ namespace WebSocketSharp.Server /// /// Either or is . /// + /// + /// is 0 or less, or 65536 or greater. + /// /// /// /// is invalid. @@ -154,20 +157,19 @@ namespace WebSocketSharp.Server if (absPath == null) throw new ArgumentNullException ("absPath"); + if (!port.IsPortNumber ()) + throw new ArgumentOutOfRangeException ("port", "Invalid port number: " + port); + string msg; if (!absPath.IsValidAbsolutePath (out msg)) throw new ArgumentException (msg, "absPath"); - if ((port == 80 && secure) || - (port == 443 && !secure)) - { - msg = String.Format ( - "Invalid pair of 'port' and 'secure': {0}, {1}", port, secure); - throw new ArgumentException (msg); - } + if ((port == 80 && secure) || (port == 443 && !secure)) + throw new ArgumentException (String.Format ( + "Invalid pair of 'port' and 'secure': {0}, {1}", port, secure)); _address = address; - _port = port > 0 ? port : secure ? 443 : 80; + _port = port; _uri = absPath.ToUri (); _secure = secure; @@ -322,8 +324,9 @@ namespace WebSocketSharp.Server _uri = uri; _address = addrs [0]; + _port = port; _secure = scheme == "wss" ? true : false; - _port = port > 0 ? port : _secure ? 443 : 80; + init (); }