I must be missing something extremely obvious but I can’t get this work properly.
The handshaking is going correctly, but as soon as I send a piece of data, I don’t get the correct data at the server.
Server:
stream.on("data", function(data) {
if(!handshake) return doHandshake(); // no problems with handshake
console.log(data);
});
Client:
ws = new WebSocket("ws://localhost:12345");
ws.onopen = function() {
ws.send(String.fromCharCode(parseInt("89", 16)));
}
What I see in the node.js console:
<Buffer 81 82 ed 68 ae 67 2f e1>
So the keys are ed 68 ae 67, and the encoded data is 2f e1. Using xor decoding the decoded data appears to be c2 89. A c2 got prepended for some unknown reason – the 89 is correct.
Weird things happen with other characters, too:
ws.send(String.fromCharCode(parseInt("ab", 16)));
I get:
<Buffer 81 82 ff 8e 45 34 3d 25>
The decoded data is c2 ab instead of ab.
I’m using the new framing format (Chrome 15) and the Windows version of node (node.exe).
- What is going wrong here?
- Is it possible to see what Chrome sends, so as to see where the problem lies?
Try with Chrome 13 (current stable channel).
Chrome 14+ uses a newer version of the Web Sockets spec which may not be implemented in your version node websocket server.
For more info, see the old version of the spec and http://chromestatus.com.
Furthermore, current versions of Chrome, even the ones that implement the new spec (Chrome 14 and 15 at this time) do not allow sending binary data.