When do you want to convert the byte order of the size end?

Source: Internet
Author: User
Tags htons
when you want to convert the size-end byte-order.

Send and receive data through the socket (on Intel's processor)
When you want to convert the size-end byte-order.

For example, send an int type of data out, do not convert.
Or both ends, you don't have to consider the conversion.
2005-6-16 13:50 Mei Kawauchi Cool when you want to convert the size-end byte-order.

Intel is a small end, and the network is big.
Casually find a socket source program a look at it and know Ah.
2005-6-16 13:53 SURFZSL when you want to convert the size-end byte-order.

In the case of uncertainty
It's best to convert to a byte sequence that is consistent with the manager.
2005-6-16 14:51 black coffee without sugar when you want to convert the size-end byte-order.

Short or Long data is best developed when communicating:
1. Use when sending: Htons (L)
2. Use when accepting: Ntohs (L)
and ignore whether the communication between the two sides need to do so ~ ~
Of course, I don't use int type of data communication, is always string communication, the sender uses sprintf organization, the receiver uses atoi to convert ~ ~
2005-6-16 15:47 Deathbravo when you want to convert the size-end byte-order.

Well said, taught.
2005-6-16 15:54 FLW when you want to convert the size-end byte-order.

[Quote] [I] original post by "Black Coffee Without Sugar" published: [i]
Short or Long data is best developed when communicating:
1. Use when sending: Htons (L)
2. Use when accepting: Ntohs (L)
and ignore whether the communication between the two sides need to do so ~ ~
Of course, I usually do not use int type of data communication, is always a string pass ... [/quote]
This statement is very correct.
2005-6-16 15:58 FLW when you want to convert the size-end byte-order.

[Quote] [I] original post by "SURFZSL" published: [i]
In the case of uncertainty
It's best to convert to a byte sequence that is consistent with the device [/quote]
Wrong.
2005-6-16 16:18 Dankey when you want to convert the size-end byte-order.

If an application layer protocol, the defined message body is
unsigned int (4 bytes);
Char[16] (16 bytes);
Like this, what should be done when sending.
2005-6-16 16:18 SURFZSL when you want to convert the size-end byte-order.

[Quote] [I] original post by "Black Coffee Without Sugar" published: [i]
Short or Long data is best developed when communicating:
1. Use when sending: Htons (L)
2. Use when accepting: Ntohs (L)
and ignore whether the communication between the two sides need to do so ~ ~
Of course, I usually do not use int type of data communication, is always a string pass ... [/quote]
: Em17:: em17:: em17:: em17:
I'd like to say that, too.
I just don't know how to say it clearly.
I remember reading that in a book.
: em06:: em06:: em06:: em06:: em06:
2005-6-16 18:15 Mike_chen when you want to convert the size-end byte-order.

For network transfer, it is best to add, most processors are big endian, byte order with the network, but some processors like space is little endian, so to avoid errors are turned
2005-6-16 18:46 Happyall when you want to convert the size-end byte-order.

Wow, this is full of pros. I am 30 years old, just beginning to learn, next time, please give a lot of advice.
2005-6-16 22:00 mq110 when you want to convert the size-end byte-order.

I exchanged data by string from the very beginning. So far, there is no problem upstairs.:)
2005-6-16 22:11 newroot_phy when you want to convert the size-end byte-order.

Ask, I remember as if the string and structure do not need to convert to network code ....
2005-6-16 22:19 mq110 when you want to convert the size-end byte-order.

Just know that the string does not.
There are also int types in the structure. or other types.
2005-6-17 08:55 Double eyelid pig. when you want to convert the size-end byte-order.

[Quote] [i] the original post by "Mike_chen"] for network transfer is best to add, most processors are big endian, byte order with the network, but some processors like space is little endian, so in order to avoid errors have turned the [/quote published: [i]

It's usually little Endian,sparc is big endian
2005-6-17 10:22 Dengyunze when you want to convert the size-end byte-order.

It's usually little Endian,sparc is big endian
-----------------------------
Positive solution.
2005-6-17 11:42 Cattiger when you want to convert the size-end byte-order.

What do you usually mean by this? What is the general, you are exposed to the general?
Most small machines adopt big endian, running UNIX systems, and some minicomputer are little endian systems, such as Compaq's VMS. Intel's processors are little endian, so Windows is the little endian system. What is the word continuation, mainly depends on the processing order of the processor.
Whether the upstairs is generally understood to be a machine with an Intel processor
2005-6-17 11:45 B46 when you want to convert the size-end byte-order.

Ha ha
2005-6-17 12:25 Narkissos when you want to convert the size-end byte-order.

Generally speaking, considering the size tail is a very formal and rigorous approach in communication software, we cannot assume that all communication works under the same architecture.
In general, in addition to the Intel 80x86 series processor is a small tail architecture, the vast majority of processors are large-tail architecture, such as the SPARC series/power series/moto 68 series. The network byte order is also a large tail.
When decoding, it is especially necessary to pay attention to the size tail problem. Use a conversion function (hton* and ntoh* Series or write-only) where you use more than one byte per place.
Therefore, when your communication software and other machines Communication software (module) communication, the general codec and other places using more than 1 bytes of data types, it is best to use the conversion function. In the partial socket processing, also needs to add the transformation function (for example IPADDR structure filling and so on), the other part already contains the related processing, may not add.

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.