javascript - How to parse binary data from websockets? -
i'm trying parse frames websockets. did fiddler, shows me binary data frame. need same result need via javascript or php (or other language). tried js
var = new websocket("ws://example.com"); a.onopen = function() { console.log("open"); a.send("test"); var b = new uint8array([8,6,7,5,3,0,9]); a.send(b.buffer); }; a.onmessage = function(e) { console.log(e.data.tostring());}; a.onclose = function() { console.log("closed");};
but didn't receive data on "a.onmessage". @ moment i've stucked. clarify question 1 more time. need simple code example parses frames websockets. example of i'm trying parse
thanks!
using dataview:
var socket = new websocket('ws://127.0.0.1:8081'); socket.binarytype = 'arraybuffer'; socket.onmessage = function (e) { var data = e.data; var dv = new dataview(data); // reads uint16 @ beginning var uint16= dv.getuint16(0); // reads next uint16 (sets 2 bytes of offset, since previous uint16 takes 2 bytes) var another_uint16= dv.getuint16(0); };
Comments
Post a Comment