Receiving Websocket Arraybuffer Data In The Browser - Receiving String Instead
I have a node.js server application and a browser client. Sending ArrayBuffer data browser -> server works perfectly, but server -> browser results in a string '[object Array
Solution 1:
send binary data use sendBytes()
method.
Solution 2:
I've been playing with websockets recently and at least this seems to work:
if(event.datainstanceofArrayBuffer)
{
var wordarray = newUint16Array(event.data);
for (var i = 0; i < wordarray.length; i++)
{
console.log(wordarray[i]);
wordarray[i]=wordarray[i]+1;
}
console.log("End of binary message");
console.log("sending changes");
ws.send(wordarray.buffer);
}
Basically I'm just creating a new array based on event.data
Post a Comment for "Receiving Websocket Arraybuffer Data In The Browser - Receiving String Instead"