Just unify little endian. Although the network byte order is big segment. However, the most popular device at present, that is, x86, is little endian, and those big endian machines also support little endian. Like Both arm and powerpc support little endian. So don’t worry about it, just use little endian.
Byte order is generally for numbers. The encoding in a string defines the order of bytes, so using the same string encoding determines the same byte order. The endianness of numbers is a historical issue and has not yet been unified. It is also very simple to deal with the endianness of numbers. Do not use the system's default digital writing or reading method to read data (because this method uses Default byte order), instead, you split the number into big-endian or little-endian bytes through the program, and manually combine the big-endian or little-endian data when reading, thus ensuring a unified character for reading and writing. Sequence.
The essential problem of byte order is the problem of type values of two bytes or more. When the network transmits data, it is a binary stream. What the data looks like when it is sent is what it is when it is received. If the machine size at both ends of the socket is The end of the struct is the same, or there is no data of more than two bytes (just like strings are data composed of a single byte, but if the struct contains multi-byte data, it needs to be converted), network byte order is useless , only the machines at both ends of the socket are different, their understanding of binary data such as 0x1234 is different, so you need to call the hton* series of functions to perform corresponding conversions to get the correct data.
Just unify little endian. Although the network byte order is big segment. However, the most popular device at present, that is, x86, is little endian, and those big endian machines also support little endian. Like Both arm and powerpc support little endian. So don’t worry about it, just use little endian.
Byte order is generally for numbers. The encoding in a string defines the order of bytes, so using the same string encoding determines the same byte order. The endianness of numbers is a historical issue and has not yet been unified. It is also very simple to deal with the endianness of numbers. Do not use the system's default digital writing or reading method to read data (because this method uses Default byte order), instead, you split the number into big-endian or little-endian bytes through the program, and manually combine the big-endian or little-endian data when reading, thus ensuring a unified character for reading and writing. Sequence.
Specify Big-Endian or Little-Endian when writing, and use the same order when reading.
The essential problem of byte order is the problem of type values of two bytes or more. When the network transmits data, it is a binary stream. What the data looks like when it is sent is what it is when it is received. If the machine size at both ends of the socket is The end of the struct is the same, or there is no data of more than two bytes (just like strings are data composed of a single byte, but if the struct contains multi-byte data, it needs to be converted), network byte order is useless , only the machines at both ends of the socket are different, their understanding of binary data such as 0x1234 is different, so you need to call the hton* series of functions to perform corresponding conversions to get the correct data.