network communication often involves byte-order conversion, then understand the host sequence and network order what similarities and differences.
① host byte order HBO (host byte order)
Use small-endian (Little-endian), low-to-high sequential storage.
The low byte is emitted at the lower address end of the memory, and the high address is discharged at the high address.
② Network byte order Nbo (NET byte order)
Use the Big Head Order (Big-endian), from high to low sequential storage.
High-bit bytes are emitted at the low address of the memory, and the low address is emitted at the high address.
The TCP/IP protocol defines the network bytes as Big-endian.
For example, the storage of 0x1234 is as follows.
byte order
|
Addr
|
Addr+1
|
Hbo
|
0x34
|
0x12
|
NBO
|
0x12
|
0x34
|
Common Conversion Functions:
①Htonl ()--------------Host to Network Long
②Ntohl ()--------------Network to Host Long
③htons ()--------------Host to Network short
④ntohs ()--------------Network to Host short
Summary of C + + technical issues-11th sequence of host sequence network in network communication