Google 到有现成的
https://www.npmjs.org/package/json-over-tcpProtocol
If you would like to implement the protocol yourself, the server will expect the following in order in the byte stream:
16-bit unsigned little-endian integer with 206 as the value. This is the protocol signature, if a message is sent without this signature a protocol error will be raised.
A 32-bit unsigned little-endian integer with the length of the message being sent as the value.
A UTF-8 string with the stringified JSON as the value (the message).
校验没必要,TCP保证通信完整性,自带校验
更低层才要校验,比如以前设计的串口通信协议,这种不可靠环境才需要自己做校验