diff --git a/Example/Example.pidb b/Example/Example.pidb index 3077a371..793717f6 100644 Binary files a/Example/Example.pidb and b/Example/Example.pidb differ diff --git a/Example/bin/Debug_Ubuntu/example.exe b/Example/bin/Debug_Ubuntu/example.exe index 3ecd8285..24eccc16 100755 Binary files a/Example/bin/Debug_Ubuntu/example.exe and b/Example/bin/Debug_Ubuntu/example.exe differ diff --git a/Example/bin/Debug_Ubuntu/example.exe.mdb b/Example/bin/Debug_Ubuntu/example.exe.mdb index b3debf12..4e9d0910 100644 Binary files a/Example/bin/Debug_Ubuntu/example.exe.mdb and b/Example/bin/Debug_Ubuntu/example.exe.mdb differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll b/Example/bin/Debug_Ubuntu/websocket-sharp.dll index 99281697..e23668f4 100755 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 9788d09c..2e2e5b1e 100644 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe b/Example1/bin/Debug_Ubuntu/example1.exe index ba8a0250..1ad7aaa3 100755 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe and b/Example1/bin/Debug_Ubuntu/example1.exe differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe.mdb b/Example1/bin/Debug_Ubuntu/example1.exe.mdb index be7f7672..1b225ce1 100644 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe.mdb and b/Example1/bin/Debug_Ubuntu/example1.exe.mdb differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll index 99281697..e23668f4 100755 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 9788d09c..2e2e5b1e 100644 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example2/Example2.pidb b/Example2/Example2.pidb index b4529a60..117cad4a 100644 Binary files a/Example2/Example2.pidb and b/Example2/Example2.pidb differ diff --git a/Example2/Program.cs b/Example2/Program.cs index 028f9aef..69d2dc75 100644 --- a/Example2/Program.cs +++ b/Example2/Program.cs @@ -7,7 +7,7 @@ namespace Example2 { public static void Main(string[] args) { - /* Single service server + // Single service server var wssv = new WebSocketServer("ws://localhost:4649"); //var wssv = new WebSocketServer(4649); //var wssv = new WebSocketServer("ws://localhost:4649"); @@ -17,9 +17,9 @@ namespace Example2 Console.WriteLine( "WebSocket Server (url: {0})\n listening on address: {1} port: {2}\n", wssv.Uri, wssv.Address, wssv.Port); - */ + - // Multi services server + /* Multi services server var wssv = new WebSocketServer(4649); wssv.AddService("/Echo"); wssv.AddService("/Chat"); @@ -27,7 +27,7 @@ namespace Example2 wssv.Start(); Console.WriteLine( "WebSocket Server listening on port: {0}\n", wssv.Port); - + */ Console.WriteLine("Press any key to stop server..."); Console.ReadLine(); diff --git a/Example2/bin/Debug_Ubuntu/example2.exe b/Example2/bin/Debug_Ubuntu/example2.exe index 08833647..05194684 100755 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe and b/Example2/bin/Debug_Ubuntu/example2.exe differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe.mdb b/Example2/bin/Debug_Ubuntu/example2.exe.mdb index 279b7260..4dd20a99 100644 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe.mdb and b/Example2/bin/Debug_Ubuntu/example2.exe.mdb differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll index 99281697..e23668f4 100755 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 9788d09c..2e2e5b1e 100644 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe b/Example3/bin/Debug_Ubuntu/Example3.exe index 05f6f7a6..f3856bb1 100755 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe and b/Example3/bin/Debug_Ubuntu/Example3.exe differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe.mdb b/Example3/bin/Debug_Ubuntu/Example3.exe.mdb index 86e73bb3..a90ec2f3 100644 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe.mdb and b/Example3/bin/Debug_Ubuntu/Example3.exe.mdb differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll index 99281697..e23668f4 100755 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 9788d09c..2e2e5b1e 100644 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index ea29019b..9f260085 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -37,6 +37,7 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.IO; using System.Linq; +using System.Net; using System.Net.Sockets; using System.Text; using WebSocketSharp.Net; @@ -166,6 +167,45 @@ namespace WebSocketSharp return false; } + public static bool IsValidWsUri(this Uri uri, out string message) + { + if (!uri.IsAbsoluteUri) + { + message = "Not absolute uri: " + uri.ToString(); + return false; + } + + var scheme = uri.Scheme; + if (scheme != "ws" && scheme != "wss") + { + message = "Unsupported WebSocket URI scheme: " + scheme; + return false; + } + + var port = uri.Port; + if (port > 0) + { + if ((scheme == "wss" && port != 443) || + (scheme != "wss" && port == 443)) + { + message = String.Format( + "Invalid pair of WebSocket URI scheme and port: {0}, {1}", scheme, port); + return false; + } + } + + var host = uri.DnsSafeHost; + var addrs = Dns.GetHostAddresses(host); + if (addrs.Length == 0) + { + message = "Invalid WebSocket URI host: " + host; + return false; + } + + message = String.Empty; + return true; + } + // Derived from System.Uri.MaybeUri method public static bool MaybeUri(this string uriString) { @@ -414,7 +454,8 @@ namespace WebSocketSharp return new Uri(uriString); } - public static void WriteContent(this HttpListenerResponse response, byte[] content) + public static void WriteContent( + this WebSocketSharp.Net.HttpListenerResponse response, byte[] content) { var output = response.OutputStream; response.ContentLength64 = content.Length; diff --git a/websocket-sharp/Server/WebSocketServerBase.cs b/websocket-sharp/Server/WebSocketServerBase.cs index 93c8fe94..3843a421 100644 --- a/websocket-sharp/Server/WebSocketServerBase.cs +++ b/websocket-sharp/Server/WebSocketServerBase.cs @@ -55,17 +55,14 @@ namespace WebSocketSharp.Server { protected WebSocketServerBase(string url) { - string msg; - if (!isValidUri(url, out msg)) - throw new ArgumentException(msg, "url"); - - init(); + init(url); } protected WebSocketServerBase(IPAddress address, int port) { - _port = port <= 0 ? 80 : port; _address = address; + _port = port <= 0 ? 80 : port; + init(); } @@ -149,48 +146,26 @@ namespace WebSocketSharp.Server { _isSelfHost = true; } - private bool isValidUri(string url, out string message) + private void init(string url) { var uri = url.ToUri(); - if (!uri.IsAbsoluteUri) - { - message = "Not absolute uri: " + url; - return false; - } + + string msg; + if (!uri.IsValidWsUri(out msg)) + throw new ArgumentException(msg, "url"); var scheme = uri.Scheme; var port = uri.Port; var host = uri.DnsSafeHost; - var ips = Dns.GetHostAddresses(host); - - if (scheme != "ws" && scheme != "wss") - { - message = "Unsupported WebSocket URI scheme: " + scheme; - return false; - } - - if ((scheme == "wss" && port != 443) || - (scheme != "wss" && port == 443)) - { - message = String.Format( - "Invalid pair of WebSocket URI scheme and port: {0}, {1}", scheme, port); - return false; - } - - if (ips.Length == 0) - { - message = "Invalid WebSocket URI host: " + host; - return false; - } + var addrs = Dns.GetHostAddresses(host); if (port <= 0) port = scheme == "ws" ? 80 : 443; - _address = ips[0]; + _address = addrs[0]; _port = port; - message = String.Empty; - return true; + init(); } private void startAcceptClientThread() diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index bc2920a3..f3b19642 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -142,17 +142,16 @@ namespace WebSocketSharp public WebSocket(string url, params string[] protocols) : this() { - var uri = new Uri(url); - if (!isValidScheme(uri)) - { - var msg = "Unsupported WebSocket URI scheme: " + uri.Scheme; + var uri = url.ToUri(); + + string msg; + if (!uri.IsValidWsUri(out msg)) throw new ArgumentException(msg, "url"); - } _uri = uri; _protocols = protocols.ToString(", "); _isClient = true; - _isSecure = _uri.Scheme == "wss" ? true : false; + _isSecure = uri.Scheme == "wss" ? true : false; } public WebSocket( @@ -597,15 +596,6 @@ namespace WebSocketSharp return true; } - private bool isValidScheme(Uri uri) - { - string scheme = uri.Scheme; - if (scheme == "ws" || scheme == "wss") - return true; - - return false; - } - private void message() { try diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll index 99281697..e23668f4 100755 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 9788d09c..2e2e5b1e 100644 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/websocket-sharp.pidb b/websocket-sharp/websocket-sharp.pidb index 9e9313ae..d743fc85 100644 Binary files a/websocket-sharp/websocket-sharp.pidb and b/websocket-sharp/websocket-sharp.pidb differ