diff --git a/Example/Example.pidb b/Example/Example.pidb index 8cb78b0d..f97c2a5f 100644 Binary files a/Example/Example.pidb and b/Example/Example.pidb differ diff --git a/Example/Program.cs b/Example/Program.cs index dcc390c2..cadd7e76 100644 --- a/Example/Program.cs +++ b/Example/Program.cs @@ -84,7 +84,10 @@ namespace Example ws.OnMessage += (sender, e) => { - enNfMessage("[WebSocket] Message", e.Data, "notification-message-im"); + if (!String.IsNullOrEmpty(e.Data)) + { + enNfMessage("[WebSocket] Message", e.Data, "notification-message-im"); + } }; ws.OnError += (sender, e) => @@ -112,7 +115,8 @@ namespace Example Console.Write("> "); data = Console.ReadLine(); - if (data == "exit" || !ws.IsConnected) + if (data == "exit") + //if (data == "exit" || !ws.IsConnected) { break; } diff --git a/Example/bin/Debug/example.exe b/Example/bin/Debug/example.exe index c3fcd35d..c85977ec 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 18456eb4..49165ddd 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 f197ebe7..b02b3b3f 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 adfc97fb..8747511f 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 e6bb92d7..8c33fead 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 fb6bbe3c..ae9e1719 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 03215224..cdff603e 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 663f255e..05a65ab3 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 948020ea..a2af80a4 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 c0161c65..fb10516d 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 194123d0..28fce593 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 c12e89fe..8b2eaf7e 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/bin/Debug/example1.exe b/Example1/bin/Debug/example1.exe index 4a6e2dfd..80cca4be 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 9436c547..c67610d1 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 f197ebe7..b02b3b3f 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 adfc97fb..8747511f 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 ac7e8e14..ab05af2d 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 619d499b..f37143be 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 03215224..cdff603e 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 663f255e..05a65ab3 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 285b9148..f30ecd63 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 c0161c65..fb10516d 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 80371aab..4c5bef5f 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 c12e89fe..8b2eaf7e 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/bin/Debug/example2.exe b/Example2/bin/Debug/example2.exe index 46954c60..14891358 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 e12044a8..bcf6cbd5 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 f197ebe7..b02b3b3f 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 adfc97fb..8747511f 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 d5a11441..db5ddd3a 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 ea4fa7a1..319e9963 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 03215224..cdff603e 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 663f255e..05a65ab3 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 b26ff6d0..f9119f9e 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 c0161c65..fb10516d 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 154ecdeb..417ab599 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 c12e89fe..8b2eaf7e 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.userprefs b/websocket-sharp.userprefs index 4f01e372..8a063dbf 100644 --- a/websocket-sharp.userprefs +++ b/websocket-sharp.userprefs @@ -1,5 +1,5 @@  - + diff --git a/websocket-sharp/Frame/WsFrame.cs b/websocket-sharp/Frame/WsFrame.cs index ae3e37d2..f9756b97 100644 --- a/websocket-sharp/Frame/WsFrame.cs +++ b/websocket-sharp/Frame/WsFrame.cs @@ -111,9 +111,18 @@ namespace WebSocketSharp.Frame { Fin = fin; Opcode = opcode; - Masked = mask; ulong dataLength = payloadData.Length; + + if (dataLength == 0) + { + Masked = Mask.UNMASK; + } + else + { + Masked = mask; + } + if (dataLength < 126) { PayloadLen = (byte)dataLength; @@ -130,6 +139,7 @@ namespace WebSocketSharp.Frame } PayloadData = payloadData; + if (Masked == Mask.MASK) { MaskingKey = new byte[4]; @@ -264,7 +274,11 @@ namespace WebSocketSharp.Frame } } // Payload Data - if (buffer3Len <= (ulong)_readBufferLen) + if (buffer3Len == 0) + { + buffer3 = new byte[]{}; + } + else if (buffer3Len <= (ulong)_readBufferLen) { buffer3 = new byte[buffer3Len]; readLen = stream.Read(buffer3, 0, (int)buffer3Len); diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 01c49ed7..61663106 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -74,6 +74,7 @@ namespace WebSocketSharp private string _protocol; private string _protocols; private volatile WsState _readyState; + private AutoResetEvent _receivedPong; private SslStream _sslStream; private TcpClient _tcpClient; private Uri _uri; @@ -116,25 +117,8 @@ namespace WebSocketSharp { get { - if (_tcpClient == null) return false; - - var socket = _tcpClient.Client; - if (!socket.Connected) return false; - - if (socket.Poll(0, SelectMode.SelectWrite) && - !socket.Poll(0, SelectMode.SelectError)) - { -// var buffer = new byte[1]; -// -// if (socket.Receive(buffer, SocketFlags.Peek) != 0) -// { -// return true; -// } - - return true; - } - - return false; + if (_readyState != WsState.OPEN) return false; + return Ping(); } } @@ -198,6 +182,7 @@ namespace WebSocketSharp _fragmentLen = 1024; // Max value is int.MaxValue - 14. _protocol = String.Empty; _readyState = WsState.CONNECTING; + _receivedPong = new AutoResetEvent(false); _unTransmittedBuffer = new SynchronizedCollection(); } @@ -894,6 +879,7 @@ namespace WebSocketSharp } else if (frame.Opcode == Opcode.PONG) {// FINAL & PONG + _receivedPong.Set(); OnMessage.Emit(this, new MessageEventArgs(frame.Opcode, frame.PayloadData)); } else @@ -913,7 +899,9 @@ namespace WebSocketSharp { case Opcode.TEXT: case Opcode.BINARY: + goto default; case Opcode.PONG: + _receivedPong.Set(); goto default; case Opcode.CLOSE: #if DEBUG @@ -1194,12 +1182,12 @@ namespace WebSocketSharp Close(CloseStatusCode.AWAY); } - public void Ping() + public bool Ping() { - Ping(String.Empty); + return Ping(String.Empty); } - public void Ping(string data) + public bool Ping(string data) { var payloadData = new PayloadData(data); @@ -1207,11 +1195,13 @@ namespace WebSocketSharp { var msg = "Ping frame must have a payload length of 125 bytes or less."; error(msg); - return; + return false; } var frame = createFrame(Fin.FINAL, Opcode.PING, payloadData); - send(frame); + if (!send(frame)) return false; + + return _receivedPong.WaitOne(5 * 1000); } public void Send(string data) diff --git a/websocket-sharp/bin/Debug/websocket-sharp.dll b/websocket-sharp/bin/Debug/websocket-sharp.dll index f197ebe7..b02b3b3f 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 adfc97fb..8747511f 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 03215224..cdff603e 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 663f255e..05a65ab3 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 c0161c65..fb10516d 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 c12e89fe..8b2eaf7e 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 c5bac055..489fcd44 100644 Binary files a/websocket-sharp/websocket-sharp.pidb and b/websocket-sharp/websocket-sharp.pidb differ