diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index e1afb2f1..10699f7a 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -40,6 +40,7 @@ /* * Contributors: * - Liryna + * - Nikola Kovacevic */ #endregion @@ -818,14 +819,12 @@ namespace WebSocketSharp /// A that represents a WebSocket URL to try. /// /// - /// When this method returns, a that represents - /// a WebSocket URL if is valid; - /// otherwise, . + /// When this method returns, a that represents a WebSocket URL, + /// or if is invalid. /// /// - /// When this method returns, a that represents - /// an error message if is invalid; - /// otherwise, . + /// When this method returns, a that represents an error message, + /// or if is valid. /// internal static bool TryCreateWebSocketUri ( this string uriString, out Uri result, out string message) @@ -839,7 +838,7 @@ namespace WebSocketSharp } var schm = uri.Scheme; - if (schm != "ws" && schm != "wss") { + if (!(schm == "ws" || schm == "wss")) { message = "The scheme part isn't 'ws' or 'wss': " + uriString; return false; } @@ -850,26 +849,22 @@ namespace WebSocketSharp } var port = uri.Port; - if (port > 0) { - if (port > 65535) { - message = "The port part is greater than 65535: " + uriString; - return false; - } - - if ((schm == "ws" && port == 443) || (schm == "wss" && port == 80)) { - message = "An invalid pair of scheme and port: " + uriString; - return false; - } - } - else { - uri = new Uri ( - String.Format ( - "{0}://{1}:{2}{3}", schm, uri.Host, schm == "ws" ? 80 : 443, uri.PathAndQuery)); + if (port > 65535) { + message = "The port part is greater than 65535: " + uriString; + return false; } - result = uri; + result = port > 0 + ? uri + : new Uri ( + String.Format ( + "{0}://{1}:{2}{3}", + schm, + uri.Host, + schm == "ws" ? 80 : 443, + uri.PathAndQuery)); + message = String.Empty; - return true; } diff --git a/websocket-sharp/Server/HttpServer.cs b/websocket-sharp/Server/HttpServer.cs index 6ff46a77..d98bc32d 100644 --- a/websocket-sharp/Server/HttpServer.cs +++ b/websocket-sharp/Server/HttpServer.cs @@ -104,12 +104,8 @@ namespace WebSocketSharp.Server /// isn't between 1 and 65535 inclusive. /// public HttpServer (int port) + : this (port, port == 443) { - if (!port.IsPortNumber ()) - throw new ArgumentOutOfRangeException ( - "port", "Not between 1 and 65535 inclusive: " + port); - - init ("*", port, port == 443); } /// @@ -127,9 +123,6 @@ namespace WebSocketSharp.Server /// A that indicates providing a secure connection or not. /// (true indicates providing a secure connection.) /// - /// - /// Pair of and is invalid. - /// /// /// isn't between 1 and 65535 inclusive. /// @@ -139,10 +132,6 @@ namespace WebSocketSharp.Server throw new ArgumentOutOfRangeException ( "port", "Not between 1 and 65535 inclusive: " + port); - if ((port == 80 && secure) || (port == 443 && !secure)) - throw new ArgumentException ( - String.Format ("An invalid pair of 'port' and 'secure': {0}, {1}", port, secure)); - init ("*", port, secure); } diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs index 20358ae2..12b1fc8c 100644 --- a/websocket-sharp/Server/WebSocketServer.cs +++ b/websocket-sharp/Server/WebSocketServer.cs @@ -112,12 +112,8 @@ namespace WebSocketSharp.Server /// isn't between 1 and 65535 inclusive. /// public WebSocketServer (int port) + : this (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); } /// @@ -188,15 +184,16 @@ namespace WebSocketSharp.Server /// A that indicates providing a secure connection or not. /// (true indicates providing a secure connection.) /// - /// - /// Pair of and is invalid. - /// /// /// isn't between 1 and 65535 inclusive. /// public WebSocketServer (int port, bool secure) - : this (System.Net.IPAddress.Any, port, secure) { + if (!port.IsPortNumber ()) + throw new ArgumentOutOfRangeException ( + "port", "Not between 1 and 65535 inclusive: " + port); + + init (System.Net.IPAddress.Any, port, secure); } /// @@ -255,15 +252,7 @@ namespace WebSocketSharp.Server /// is . /// /// - /// - /// isn't a local IP address. - /// - /// - /// -or- - /// - /// - /// Pair of and is invalid. - /// + /// isn't a local IP address. /// /// /// isn't between 1 and 65535 inclusive. @@ -280,10 +269,6 @@ namespace WebSocketSharp.Server throw new ArgumentOutOfRangeException ( "port", "Not between 1 and 65535 inclusive: " + port); - if ((port == 80 && secure) || (port == 443 && !secure)) - throw new ArgumentException ( - String.Format ("An invalid pair of 'port' and 'secure': {0}, {1}", port, secure)); - init (address, port, secure); }