diff --git a/Example/Example.pidb b/Example/Example.pidb index e0dc4a16..6551e3b0 100644 Binary files a/Example/Example.pidb and b/Example/Example.pidb differ diff --git a/Example/Program.cs b/Example/Program.cs index f3c763db..4fc67ff8 100644 --- a/Example/Program.cs +++ b/Example/Program.cs @@ -49,7 +49,7 @@ namespace Example WaitCallback notifyMsg = state => { - while (ts.Enabled) + while (ts.Enabled || _msgQ.Count > 0) { Thread.Sleep(500); @@ -73,9 +73,9 @@ namespace Example ThreadPool.QueueUserWorkItem(notifyMsg); - using (WebSocket ws = new WebSocket("ws://echo.websocket.org", "echo")) + //using (WebSocket ws = new WebSocket("ws://echo.websocket.org", "echo")) //using (WebSocket ws = new WebSocket("wss://echo.websocket.org", "echo")) - //using (WebSocket ws = new WebSocket("ws://localhost:4649")) + using (WebSocket ws = new WebSocket("ws://localhost:4649")) { ws.OnOpen += (sender, e) => { @@ -116,7 +116,7 @@ namespace Example Console.Write("> "); data = Console.ReadLine(); if (data == "exit") - //if (data == "exit" || !ws.IsConnected) + //if (data == "exit" || !ws.IsKeepAlive) { break; } diff --git a/Example/bin/Debug/example.exe b/Example/bin/Debug/example.exe index ef30e8ca..db440730 100755 Binary files a/Example/bin/Debug/example.exe and b/Example/bin/Debug/example.exe differ diff --git a/Example/bin/Debug/example.exe.mdb b/Example/bin/Debug/example.exe.mdb index 043dfc2b..dfe384b5 100644 Binary files a/Example/bin/Debug/example.exe.mdb and b/Example/bin/Debug/example.exe.mdb differ diff --git a/Example/bin/Debug/websocket-sharp.dll b/Example/bin/Debug/websocket-sharp.dll index 615a2c62..0901b46b 100755 Binary files a/Example/bin/Debug/websocket-sharp.dll and b/Example/bin/Debug/websocket-sharp.dll differ diff --git a/Example/bin/Debug/websocket-sharp.dll.mdb b/Example/bin/Debug/websocket-sharp.dll.mdb index c4c850c1..615a3a20 100644 Binary files a/Example/bin/Debug/websocket-sharp.dll.mdb and b/Example/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example/bin/Debug_Ubuntu/example.exe b/Example/bin/Debug_Ubuntu/example.exe index 39c29468..a1ecdde1 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 6222a2ec..121eb411 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 7d6a7a5d..49918c07 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 0eba2896..e5032846 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/Example/bin/Release/example.exe b/Example/bin/Release/example.exe index 1a78014f..6fd15adc 100755 Binary files a/Example/bin/Release/example.exe and b/Example/bin/Release/example.exe differ diff --git a/Example/bin/Release/websocket-sharp.dll b/Example/bin/Release/websocket-sharp.dll index 0de3f814..cae2760e 100755 Binary files a/Example/bin/Release/websocket-sharp.dll and b/Example/bin/Release/websocket-sharp.dll differ diff --git a/Example/bin/Release_Ubuntu/example.exe b/Example/bin/Release_Ubuntu/example.exe index 8be14f93..4199bbd5 100755 Binary files a/Example/bin/Release_Ubuntu/example.exe and b/Example/bin/Release_Ubuntu/example.exe differ diff --git a/Example/bin/Release_Ubuntu/websocket-sharp.dll b/Example/bin/Release_Ubuntu/websocket-sharp.dll index 271bdcc5..d8d1e088 100755 Binary files a/Example/bin/Release_Ubuntu/websocket-sharp.dll and b/Example/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/Example1/AudioStreamer.cs b/Example1/AudioStreamer.cs index 110a23a9..8a64e1e5 100644 --- a/Example1/AudioStreamer.cs +++ b/Example1/AudioStreamer.cs @@ -124,7 +124,7 @@ namespace Example1 _notifyMsgState = new ThreadState(); _notifyMsg = (state) => { - while (_notifyMsgState.Enabled) + while (_notifyMsgState.Enabled || _msgQ.Count > 0) { Thread.Sleep(500); @@ -197,7 +197,7 @@ namespace Example1 float[,] buffer_array = new float[ch_num, buffer_length]; int offset = 9; - ch_num.Times(i => + ((int)ch_num).Times(i => { buffer_length.Times(j => { diff --git a/Example1/Example1.pidb b/Example1/Example1.pidb index 8b9cc32a..d594e6bc 100644 Binary files a/Example1/Example1.pidb and b/Example1/Example1.pidb differ diff --git a/Example1/bin/Debug/example1.exe b/Example1/bin/Debug/example1.exe index db9115d4..17fa2131 100755 Binary files a/Example1/bin/Debug/example1.exe and b/Example1/bin/Debug/example1.exe differ diff --git a/Example1/bin/Debug/example1.exe.mdb b/Example1/bin/Debug/example1.exe.mdb index dd867ddb..5391beb5 100644 Binary files a/Example1/bin/Debug/example1.exe.mdb and b/Example1/bin/Debug/example1.exe.mdb differ diff --git a/Example1/bin/Debug/websocket-sharp.dll b/Example1/bin/Debug/websocket-sharp.dll index 615a2c62..0901b46b 100755 Binary files a/Example1/bin/Debug/websocket-sharp.dll and b/Example1/bin/Debug/websocket-sharp.dll differ diff --git a/Example1/bin/Debug/websocket-sharp.dll.mdb b/Example1/bin/Debug/websocket-sharp.dll.mdb index c4c850c1..615a3a20 100644 Binary files a/Example1/bin/Debug/websocket-sharp.dll.mdb and b/Example1/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe b/Example1/bin/Debug_Ubuntu/example1.exe index bf5dd950..9ff655e7 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 a5abf751..6dcbf017 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 7d6a7a5d..49918c07 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 0eba2896..e5032846 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/Example1/bin/Release/example1.exe b/Example1/bin/Release/example1.exe index bbd1e4bf..437b2c97 100755 Binary files a/Example1/bin/Release/example1.exe and b/Example1/bin/Release/example1.exe differ diff --git a/Example1/bin/Release/websocket-sharp.dll b/Example1/bin/Release/websocket-sharp.dll index 0de3f814..cae2760e 100755 Binary files a/Example1/bin/Release/websocket-sharp.dll and b/Example1/bin/Release/websocket-sharp.dll differ diff --git a/Example1/bin/Release_Ubuntu/example1.exe b/Example1/bin/Release_Ubuntu/example1.exe index a6ab5310..5b92a16b 100755 Binary files a/Example1/bin/Release_Ubuntu/example1.exe and b/Example1/bin/Release_Ubuntu/example1.exe differ diff --git a/Example1/bin/Release_Ubuntu/websocket-sharp.dll b/Example1/bin/Release_Ubuntu/websocket-sharp.dll index 271bdcc5..d8d1e088 100755 Binary files a/Example1/bin/Release_Ubuntu/websocket-sharp.dll and b/Example1/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/Example2/Echo.cs b/Example2/Echo.cs index a75962f8..49cdc647 100644 --- a/Example2/Echo.cs +++ b/Example2/Echo.cs @@ -10,5 +10,10 @@ namespace Example2 { Send(e.Data); } + + protected override void onClose(object sender, CloseEventArgs e) + { + Console.WriteLine("[Echo] Close({0}: {1})", (ushort)e.Code, e.Code); + } } } diff --git a/Example2/Example2.pidb b/Example2/Example2.pidb index 1a7ea415..4d9246a4 100644 Binary files a/Example2/Example2.pidb and b/Example2/Example2.pidb differ diff --git a/Example2/Program.cs b/Example2/Program.cs index aa659658..388a1431 100644 --- a/Example2/Program.cs +++ b/Example2/Program.cs @@ -9,7 +9,7 @@ namespace Example2 { //var wssv = new WebSocketServer("ws://localhost:4649"); //var wssv = new WebSocketServer("ws://localhost:4649"); - var wssv = new WebSocketServer("/", 4649); + var wssv = new WebSocketServer(4649); wssv.Start(); Console.WriteLine( diff --git a/Example2/bin/Debug/example2.exe b/Example2/bin/Debug/example2.exe index 36d05d35..f649e800 100755 Binary files a/Example2/bin/Debug/example2.exe and b/Example2/bin/Debug/example2.exe differ diff --git a/Example2/bin/Debug/example2.exe.mdb b/Example2/bin/Debug/example2.exe.mdb index c2fc78bd..bc9dee95 100644 Binary files a/Example2/bin/Debug/example2.exe.mdb and b/Example2/bin/Debug/example2.exe.mdb differ diff --git a/Example2/bin/Debug/websocket-sharp.dll b/Example2/bin/Debug/websocket-sharp.dll index 615a2c62..0901b46b 100755 Binary files a/Example2/bin/Debug/websocket-sharp.dll and b/Example2/bin/Debug/websocket-sharp.dll differ diff --git a/Example2/bin/Debug/websocket-sharp.dll.mdb b/Example2/bin/Debug/websocket-sharp.dll.mdb index c4c850c1..615a3a20 100644 Binary files a/Example2/bin/Debug/websocket-sharp.dll.mdb and b/Example2/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe b/Example2/bin/Debug_Ubuntu/example2.exe index 915409c8..43edace7 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 cff75eaa..d64e6578 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 7d6a7a5d..49918c07 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 0eba2896..e5032846 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/Example2/bin/Release/example2.exe b/Example2/bin/Release/example2.exe index d9a96bd7..72fab764 100755 Binary files a/Example2/bin/Release/example2.exe and b/Example2/bin/Release/example2.exe differ diff --git a/Example2/bin/Release/websocket-sharp.dll b/Example2/bin/Release/websocket-sharp.dll index 0de3f814..cae2760e 100755 Binary files a/Example2/bin/Release/websocket-sharp.dll and b/Example2/bin/Release/websocket-sharp.dll differ diff --git a/Example2/bin/Release_Ubuntu/example2.exe b/Example2/bin/Release_Ubuntu/example2.exe index 57b99921..387bc3b7 100755 Binary files a/Example2/bin/Release_Ubuntu/example2.exe and b/Example2/bin/Release_Ubuntu/example2.exe differ diff --git a/Example2/bin/Release_Ubuntu/websocket-sharp.dll b/Example2/bin/Release_Ubuntu/websocket-sharp.dll index 271bdcc5..d8d1e088 100755 Binary files a/Example2/bin/Release_Ubuntu/websocket-sharp.dll and b/Example2/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index e71b67c9..670aa64b 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -149,48 +149,36 @@ namespace WebSocketSharp return subArray; } - public static void Times(this T n, Action act) - where T : struct + public static void Times(this int n, Action act) { - if (typeof(T) != typeof(byte) && - typeof(T) != typeof(Int16) && - typeof(T) != typeof(Int32) && - typeof(T) != typeof(Int64) && - typeof(T) != typeof(UInt16) && - typeof(T) != typeof(UInt32) && - typeof(T) != typeof(UInt64)) - { - throw new NotSupportedException("Not supported Struct type: " + typeof(T).ToString()); - } + ((ulong)n).Times(act); + } - ulong m = (ulong)(object)n; + public static void Times(this uint n, Action act) + { + ((ulong)n).Times(act); + } - for (ulong i = 0; i < m; i++) - { + public static void Times(this ulong n, Action act) + { + for (ulong i = 0; i < n; i++) act(); - } } - public static void Times(this T n, Action act) - where T : struct + public static void Times(this int n, Action act) { - if (typeof(T) != typeof(byte) && - typeof(T) != typeof(Int16) && - typeof(T) != typeof(Int32) && - typeof(T) != typeof(Int64) && - typeof(T) != typeof(UInt16) && - typeof(T) != typeof(UInt32) && - typeof(T) != typeof(UInt64)) - { - throw new NotSupportedException("Not supported Struct type: " + typeof(T).ToString()); - } + ((ulong)n).Times(act); + } - ulong m = (ulong)(object)n; + public static void Times(this uint n, Action act) + { + ((ulong)n).Times(act); + } - for (ulong i = 0; i < m; i++) - { + public static void Times(this ulong n, Action act) + { + for (ulong i = 0; i < n; i++) act(i); - } } public static T To(this byte[] src, ByteOrder srcOrder) diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs index f9f5d525..60b2b5b8 100644 --- a/websocket-sharp/Server/WebSocketServer.cs +++ b/websocket-sharp/Server/WebSocketServer.cs @@ -51,7 +51,7 @@ namespace WebSocketSharp.Server { #endregion - #region Constructor + #region Constructors public WebSocketServer(string url) { @@ -83,6 +83,11 @@ namespace WebSocketSharp.Server { _services = new Dictionary(); } + public WebSocketServer(int port) + : this("/", port) + { + } + public WebSocketServer(string absPath, int port) { _uri = new Uri(absPath, UriKind.Relative); @@ -177,7 +182,7 @@ namespace WebSocketSharp.Server { private void startService(TcpClient client) { - WaitCallback startCb = (state) => + WaitCallback startSv = (state) => { try { var socket = new WebSocket(_uri, client); @@ -188,7 +193,7 @@ namespace WebSocketSharp.Server { error(ex.Message); } }; - ThreadPool.QueueUserWorkItem(startCb); + ThreadPool.QueueUserWorkItem(startSv); } #endregion diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 598c21d4..8518d6ab 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -69,6 +69,7 @@ namespace WebSocketSharp private Object _forSend; private int _fragmentLen; private bool _isClient; + private bool _isSecure; private Thread _msgThread; private NetworkStream _netStream; private string _protocol; @@ -109,6 +110,7 @@ namespace WebSocketSharp _tcpClient = tcpClient; _endPoint = (IPEndPoint)_tcpClient.Client.LocalEndPoint; _isClient = false; + _isSecure = _endPoint.Port == 443 ? true : false; } #endregion @@ -119,7 +121,6 @@ namespace WebSocketSharp : this() { _uri = new Uri(url); - if (!isValidScheme(_uri)) { var msg = "Unsupported WebSocket URI scheme: " + _uri.Scheme; @@ -128,6 +129,7 @@ namespace WebSocketSharp _protocols = protocols.ToString(", "); _isClient = true; + _isSecure = _uri.Scheme == "wss" ? true : false; } public WebSocket( @@ -179,7 +181,7 @@ namespace WebSocketSharp get { return _extensions; } } - public bool IsConnected { + public bool IsKeepAlive { get { if (_readyState != WsState.OPEN) return false; @@ -190,10 +192,7 @@ namespace WebSocketSharp public bool IsSecure { get { - if (_endPoint.Port == 443) - return true; - - return false; + return _isSecure; } } @@ -360,21 +359,19 @@ namespace WebSocketSharp private void createClientStream() { - string scheme = _uri.Scheme; - string host = _uri.DnsSafeHost; - int port = _uri.Port; - + var host = _uri.DnsSafeHost; + var port = _uri.Port; if (port <= 0) { port = 80; - if (scheme == "wss") + if (IsSecure) port = 443; } _tcpClient = new TcpClient(host, port); _netStream = _tcpClient.GetStream(); - if (scheme == "wss") + if (IsSecure) { RemoteCertificateValidationCallback validation = (sender, certificate, chain, sslPolicyErrors) => { diff --git a/websocket-sharp/bin/Debug/websocket-sharp.dll b/websocket-sharp/bin/Debug/websocket-sharp.dll index 615a2c62..0901b46b 100755 Binary files a/websocket-sharp/bin/Debug/websocket-sharp.dll and b/websocket-sharp/bin/Debug/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb b/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb index c4c850c1..615a3a20 100644 Binary files a/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb and b/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll index 7d6a7a5d..49918c07 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 0eba2896..e5032846 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/bin/Release/websocket-sharp.dll b/websocket-sharp/bin/Release/websocket-sharp.dll index 0de3f814..cae2760e 100755 Binary files a/websocket-sharp/bin/Release/websocket-sharp.dll and b/websocket-sharp/bin/Release/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll index 271bdcc5..d8d1e088 100755 Binary files a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/websocket-sharp.pidb b/websocket-sharp/websocket-sharp.pidb index 82ca1a28..e4755b18 100644 Binary files a/websocket-sharp/websocket-sharp.pidb and b/websocket-sharp/websocket-sharp.pidb differ