WebSocket
WebSocket support, but not limited to web scenarios, is a well-encapsulated socket communication protocol that can be used to do c-s communication.
You can binaryType
specify the data flow format for communication by setting it for simple and efficient transmission:
ws_account.binaryType = ‘arraybuffer‘;
Protobuffer
Protobuffer is a data protocol, and the equivalent role has XML, JSON. The biggest bit is the transfer byte savings, but the data readability is poor and the buffer data needs to be parsed and encapsulated by defining the proto data structure.
Using Protobuffer requires byte manipulation of the data, ArrayBuffer in JavaScript, and buffer in Nodejs. ArrayBuffer in JavaScript is usually read and written by DataView.
var buf = new Int8Array([1,2,3,4,5,6,7,8]);var buffer = new ArrayBuffer(buf.length + 4);var dv = new DataView(buffer);dv.setInt32(0, msgid, true);for (let i=0;i<buf.length;i++) { dv.setInt8(4+i, buf[i]);}
JSON expand Display
JSON comes with the ability to expand and beautify, combined with highlight and other plug-ins to quickly beautify the JSON object
JSON.stringify(msg, undefined, 4);
Websocket,protobuffer,hightlight,json, etc., recently encountered some knowledge points summary