Summary of C + + technical issues-11th sequence of host sequence network in network communication

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.