diff --git a/websocket-sharp.userprefs b/websocket-sharp.userprefs index 40b366ad..c1a56c57 100644 --- a/websocket-sharp.userprefs +++ b/websocket-sharp.userprefs @@ -1,8 +1,8 @@  - + - + diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index f92f94a8..865fd211 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -248,53 +248,12 @@ namespace WebSocketSharp private void doHandshake() { - string path = uri.PathAndQuery; - string host = uri.DnsSafeHost; - string origin = "http://" + host; - - int port = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Port; - if (port != 80) - { - host += ":" + port; - } - - string subProtocol = protocol != String.Empty #if !CHALLENGE - ? String.Format("WebSocket-Protocol: {0}\r\n", protocol) -#else - ? String.Format("Sec-WebSocket-Protocol: {0}\r\n", protocol) -#endif - : protocol; -#if !CHALLENGE - string secKeys = String.Empty; - string key3ToAscii = String.Empty; + string request = createOpeningHandshake(); #else - Random rand = new Random(); - - uint key1, key2; - string secKey1 = rand.GenerateSecKey(out key1); - string secKey2 = rand.GenerateSecKey(out key2); - - byte[] key3 = new byte[8].InitializeWithPrintableASCII(rand); - - string secKeys = "Sec-WebSocket-Key1: {0}\r\n" + - "Sec-WebSocket-Key2: {1}\r\n"; - secKeys = String.Format(secKeys, secKey1, secKey2); - - string key3ToAscii = Encoding.ASCII.GetString(key3); - - byte[] expectedRes = createExpectedRes(key1, key2, key3); - byte[] actualRes = new byte[16]; + byte[] expectedRes, actualRes = new byte[16]; + string request = createOpeningHandshake(out expectedRes); #endif - string request = "GET " + path + " HTTP/1.1\r\n" + - "Upgrade: WebSocket\r\n" + - "Connection: Upgrade\r\n" + - subProtocol + - "Host: " + host + "\r\n" + - "Origin: " + origin + "\r\n" + - secKeys + - "\r\n" + - key3ToAscii; #if DEBUG Console.WriteLine("WS: Info @doHandshake: Handshake from client: \n{0}", request); #endif @@ -374,6 +333,60 @@ namespace WebSocketSharp ReadyState = WsState.OPEN; } +#if !CHALLENGE + private string createOpeningHandshake() +#else + private string createOpeningHandshake(out byte[] expectedRes) +#endif + { + string path = uri.PathAndQuery; + string host = uri.DnsSafeHost; + string origin = "http://" + host; + + int port = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Port; + if (port != 80) + { + host += ":" + port; + } + + string subProtocol = protocol != String.Empty +#if !CHALLENGE + ? String.Format("WebSocket-Protocol: {0}\r\n", protocol) +#else + ? String.Format("Sec-WebSocket-Protocol: {0}\r\n", protocol) +#endif + : protocol; +#if !CHALLENGE + string secKeys = String.Empty; + string key3ToAscii = String.Empty; +#else + Random rand = new Random(); + + uint key1, key2; + string secKey1 = rand.GenerateSecKey(out key1); + string secKey2 = rand.GenerateSecKey(out key2); + + byte[] key3 = new byte[8].InitializeWithPrintableASCII(rand); + + string secKeys = "Sec-WebSocket-Key1: {0}\r\n" + + "Sec-WebSocket-Key2: {1}\r\n"; + secKeys = String.Format(secKeys, secKey1, secKey2); + + string key3ToAscii = Encoding.ASCII.GetString(key3); + + expectedRes = createExpectedRes(key1, key2, key3); +#endif + return "GET " + path + " HTTP/1.1\r\n" + + "Upgrade: WebSocket\r\n" + + "Connection: Upgrade\r\n" + + subProtocol + + "Host: " + host + "\r\n" + + "Origin: " + origin + "\r\n" + + secKeys + + "\r\n" + + key3ToAscii; + } + private byte[] createExpectedRes(uint key1, uint key2, byte[] key3) { byte[] key1Bytes = BitConverter.GetBytes(key1); diff --git a/websocket-sharp/bin/Debug/websocket-sharp.dll b/websocket-sharp/bin/Debug/websocket-sharp.dll index 52cff40b..b33f3d66 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 f3856d9e..84b9cea6 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 bd2afbcb..80b26186 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 7d459892..03f71e02 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 43cbfdf3..82caef18 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/websocket-sharp.pidb b/websocket-sharp/websocket-sharp.pidb index 599f6061..f9110761 100644 Binary files a/websocket-sharp/websocket-sharp.pidb and b/websocket-sharp/websocket-sharp.pidb differ diff --git a/wsclient/bin/Debug/websocket-sharp.dll b/wsclient/bin/Debug/websocket-sharp.dll index 52cff40b..b33f3d66 100755 Binary files a/wsclient/bin/Debug/websocket-sharp.dll and b/wsclient/bin/Debug/websocket-sharp.dll differ diff --git a/wsclient/bin/Debug/websocket-sharp.dll.mdb b/wsclient/bin/Debug/websocket-sharp.dll.mdb index f3856d9e..84b9cea6 100644 Binary files a/wsclient/bin/Debug/websocket-sharp.dll.mdb and b/wsclient/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/wsclient/bin/Debug/wsclient.exe b/wsclient/bin/Debug/wsclient.exe index 2c27d11d..8f3d39f1 100755 Binary files a/wsclient/bin/Debug/wsclient.exe and b/wsclient/bin/Debug/wsclient.exe differ diff --git a/wsclient/bin/Debug/wsclient.exe.mdb b/wsclient/bin/Debug/wsclient.exe.mdb index abc5b466..b7038045 100644 Binary files a/wsclient/bin/Debug/wsclient.exe.mdb and b/wsclient/bin/Debug/wsclient.exe.mdb differ diff --git a/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll b/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll index bd2afbcb..80b26186 100755 Binary files a/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll and b/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 7d459892..03f71e02 100644 Binary files a/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/wsclient/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/wsclient/bin/Debug_Ubuntu/wsclient.exe b/wsclient/bin/Debug_Ubuntu/wsclient.exe index d3f70e3f..246a33c4 100755 Binary files a/wsclient/bin/Debug_Ubuntu/wsclient.exe and b/wsclient/bin/Debug_Ubuntu/wsclient.exe differ diff --git a/wsclient/bin/Debug_Ubuntu/wsclient.exe.mdb b/wsclient/bin/Debug_Ubuntu/wsclient.exe.mdb index e878c1b1..d3cb2c6a 100644 Binary files a/wsclient/bin/Debug_Ubuntu/wsclient.exe.mdb and b/wsclient/bin/Debug_Ubuntu/wsclient.exe.mdb differ diff --git a/wsclient/bin/Release/websocket-sharp.dll b/wsclient/bin/Release/websocket-sharp.dll index 43cbfdf3..82caef18 100755 Binary files a/wsclient/bin/Release/websocket-sharp.dll and b/wsclient/bin/Release/websocket-sharp.dll differ diff --git a/wsclient/bin/Release/wsclient.exe b/wsclient/bin/Release/wsclient.exe index 1fd98d25..432e7468 100755 Binary files a/wsclient/bin/Release/wsclient.exe and b/wsclient/bin/Release/wsclient.exe differ