javascript - Deconstruct/decode Websocket frames like Google Chrome does -
javascript - Deconstruct/decode Websocket frames like Google Chrome does -
i'm connecting website via websocket connection (client server), know how encode info , write server (using net
module in node.js) when i'm reading info odd characters in front end of of import data, if i'm suppose get:
// info needed on left , info i'm receiving websocket on right 'inited\r\n' -> '�inited\r\n' 'n:2\r\n' -> '�n:2\r\n'
this how getting info server
klass.prototype.connect = function(){ // this.port equal 8080 , exact server varys, it's not of import anyways since problem decoding info properly. var = this; var buffer = ""; this.socket = new net.createconnection(this.port, this.server); this.socket .on("connect", function(){ that.sendhandshake(); // sends standard client server handshake }) .on("data", function(recv){ // .split('\r\n\r\n').join('\r\n') needed separate server handshake info trying parse buffer += recv.tostring('utf-8').split('\r\n\r\n').join('\r\n'); while (buffer){ var offset = buffer.indexof('\r\n'); if (offset < 0) return; var msg = buffer.slice(0, offset); // parsemsg(msg) buffer = buffer.slice(offset + 3); } }); };
i doing lot of things improperly in code above, i'm not quite sure how best got now.
problem don't know how remove mystery/special characters. there 1 mystery/special character, other times there multiple ones depending on info never after of import info need check.
when utilize google chrome , view info on through tools->javascript console->network tab , find websocket stream i'm looking google parses correctly. know it's possible since google chrome shows right frames, how deconstruct/decode info can view right frames on terminal?
i don't need in particular language long works should able port it, prefer examples/answers in node.js since programming language using connect server.
javascript node.js websocket
Comments
Post a Comment