I'm trying to send typed arrays (Uint16Array) from a browser to node.js trough a binary socket but I'm getting incoherent values when I receive them in node.
I read lot of documentation but there is something that I don't understand...
Here is the browser-side code :
var ws = new WebSocket('ws://127.0.0.1:8080');
ws.binaryType = "arraybuffer";
var message = new Uint16Array(3);
message[0] = 123;
message[1] = 456;
message[2] = 789;
ws.onopen = function() {
ws.send(message.buffer);
};
And this is the server code (I'm using https://github.com/einaros/ws) :
var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer({port: 8080});
wss.on('connection', function(ws) {
ws.on('message', function(buffer, flags) {
var message = new Uint16Array(buffer);
console.log(message[0]); // 123
console.log(message[1]); // 0
console.log(message[2]); // 200
});
});
Would you have any idea where this variation could come from? Thanks to all !
Dimitri