I am testing the latest version of Chrome (website version 13).
Here my simple client page is at http://127.0.0.1/folder/default.aspx :
<script type="text/javascript"> var socket = new WebSocket('ws://localhost:8181/websession'); socket.onopen = function () { alert('handshake successfully established. May send data now...'); }; socket.onclose = function () { alert('connection closed'); }; socket.onmessage = function(msg) { alert(msg); }; </script>
And here is my listener (C #)
var listener = new TcpListener(IPAddress.Loopback, 8181); listener.Start(); while (true) { Console.WriteLine("Listening..."); using (var client = listener.AcceptTcpClient()) using (var stream = client.GetStream()) using (var reader = new StreamReader(stream)) using (var writer = new StreamWriter(stream)) { writer.WriteLine("HTTP/1.1 101 Web Socket Protocol Handshake"); writer.WriteLine("Upgrade: WebSocket"); writer.WriteLine("Connection: Upgrade"); writer.WriteLine("WebSocket-Origin: http://127.0.0.1"); writer.WriteLine("WebSocket-Location: ws://localhost:8181/websession"); writer.WriteLine(""); } Console.WriteLine("Finished"); }
When I start the server and then load the client page, it only says "connection closed" .
Can someone tell me how to properly execute this handshake? As far as I can tell from the documentation and the previous questions, the answer that I send back to the client looks correct.
source share