When we use TCP to communicate, since TCP is stream-oriented, we need to parse the stream. That is, unpacking, parsing the stream into segments of data we need. This solution is a processing solution implemented by Node.Js.
The data to be sent is encoded according to the protocol, and the data data is divided into two parts: header + body . The header has a fixed length ( 2 byte ), and header describes the length of the body data. Since header is fixed-length, body 's content can be parsed through header .
By default header we use 2 Byte storage space, that is, the maximum body length of Int16 is 32767 , that is, 16M .

As shown in the figure above, we can first take out the first two bits of the data stream, read the content 0x00, 0x02 converted into an integer is 2, and then read out the 3rd and 4th bits body 0x61, 0x62 .
Install
Getting Started
API Reference
Examples
Solve the problem of "sticking packets" for TCP network transmission (Classic)
In real scenarios, the client is written in other languages, such as C language running on a microcontroller. At this time, you can package the basic schematic diagram by yourself, as the rules show:
data = header(body.length) + bodyMIT