iOS Socket considerations

Source: Internet
Author: User
Different machines have different byte storage order for variables, some use big-end mode (Big-endian), and some use small-terminal mode (Little-endian).
Big-endian mode means that high byte data is stored at a low address, and low byte data is placed at a high address.
Small-end mode means that low byte data is stored at a low address, and high byte data is placed at a high address.

Data transmission on the network, because the two ends of the data transmission may correspond to different hardware platforms, the use of the storage byte order may also be inconsistent, so the TCP/IP protocol on the network must use the network byte order (that is, big-end mode).

By analyzing the storage principle of the size end, it can be found that for char data, because it occupies only one byte, this problem does not exist, which is one of the reasons to define the data buffer as a char type in general. Non-char data, such as IP address, port number, and so on, must be converted to a big end mode before the data is sent to the network, and then converted to a storage mode that conforms to the receiving host after receiving the data.

So we need to change the data for the iOS to the big End storage::: T16 = Cfswapint16hosttobig (_api_ret);

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.

Tags Index: