1. Byte order
Byte order refers to the order in memory of data that occupies more than one byte of memory, usually with a small, big-endian byte order. Small-endian byte-order refers to low-byte data stored at low memory address, high-byte data stored at high memory address; Big endian byte order is high-byte data is stored at low address, low-byte data is stored at high address. when reading data from a computer, it is from high address to low address, while storing data in the opposite direction!
2. Host byte order to network byte order
The PC based on X86 platform is small endian, while some embedded platforms are byte order. As a result, more than 1 bytes of data such as int, uint16, UInt32, etc., should be changed in the storage order on these embedded platforms. In general, we believe that the sequence of bytes transmitted in the air is the standard order of the network byte order, taking into account the consistency with the protocol and interoperability with other platform products, when the packet is sent in the program, the host byte order is converted to the network byte order, and the packet is converted to the host byte order by the receiving packet.
3. Network byte order
Network byte order is a well-defined data representation format in TCP/IP, which is independent of the specific CPU type, operating system and so on, so that the data can be interpreted correctly when transferring between different hosts. The network byte order is sorted by the big endian (endian mode) .
4. Example diagram:
X86 platform-based PC sends a byte order of an int (32-bit) integer over the network