I am trying to get a simple WebSocket example to work on my machine (localhost), I got JavaScript and C# running just fine and connecting, except that Chrome disconnects after handshake.
I have searched all morning and I think it has something to do with the same domain policy, as another “question” suggests, I have updated my browser to the latest version (12.xxx).
However I couldnt find a solution to my problem.
I am using on the C# side:
ConnectionOrigin = "http://localhost:8080";
ServerLocation = "ws://localhost:8181/test";
And I am running the JavaScript using a normal HTML file open straight from disk (file:/// on the url bar). I have also tried using XAMPP to host it locally but I always have the same problem.
Attached goes the log output of the C# program:
New connection from 127.0.0.1:8181 requested. Handshaking ...
Reading handshake ...
GET /test HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: localhost:8181
Origin: null
Sec-WebSocket-Key1: R 506 I 2D }6 qFB G0`@88J? 4
Sec-WebSocket-Key2: y 20 8403!24 L 5 8
Sending handshake ...
HTTP/1.1 101 Web Socket Protocol Handshake
Upgrade: WebSocket
Connection: Upgrade
WebSocket-Origin: http://localhost:8080
WebSocket-Location: ws://localhost:8181/test
New connection from 127.0.0.1:8181 established.
http://localhost:8080
Data sent to the client ["Time at the server: 23-07-2011 12:57:27"]
Client disconnected.
Waiting for another connection attempt ...
In case of this request:
the response must be:
So:
WebSocketand notWeb Socketin the first line.Sec-WebSocket-...and notWebSocket-....\r\nand not\n(in case you didn’t already).On a side note, you might want to consult
chrome://net-internals/(theEventstab and then look for the appropriateSOCKET_STREAM) to see what response Chrome actually received.