[Reading Notes] iOS-deep anatomy of peer-to-peer networks, Reading Notes ios-

Source: Internet
Author: User

[Reading Notes] iOS-deep anatomy of peer-to-peer networks, Reading Notes ios-

The Protocol itself is a custom protocol running on UDP. I decided to use a custom protocol as simple as that. First, the current task seems simple enough, so it is easier to build a custom protocol directly than to try to improve a current protocol. Second, custom protocols can minimize overhead and improve performance as much as possible. Finally, this is a good teaching practice.

 

TCP is a stream protocol. Every time you view a webpage, the TCP protocol is used to check emails or download files. Essentially, TCP establishes a two-way pipeline between two computers and does its best to conceal the reliability and uncertainty of its underlying network.

 

UDP exposes many uncertainties. It uses a checksum to ensure that the cracked data is not transmitted, but it does not try to mask the problem. If a vro decides to discard a data packet, the data will never be received. If an earlier data packet is delayed so that it arrives late, the makeup of the data will be out of order. Therefore, each application must take measures to compensate these problems.

 

However, UDP uses fewer resources and provides better performance. Essentially, TCP is based on connections. Therefore, each remote device that the application needs to communicate with must establish and maintain connections. If you plan to support a large number of such devices, the overhead will be very high. In addition, TCP will try to recover, but it takes time to recover. In contrast, UDP only skips packet loss and continues to send subsequent updates. If you are pursuing performance and can cope with data loss, UDP is the top choice. This is why UDP is used in vocie-over-IP applications, online games, and the example project.

 

The coordinate is a 32-bit signed integer. This is a little useful, because the iPhone screen is only 320*480, but this can leave room for the future. As for the color, there is no need to use a type greater than a single byte to represent each color component. In this way, the value range of each component is 0 ~ 255, which is the maximum color resolution that most screens can reproduce.

 

The C compiler always sacrifices space for speed. If the data processed by the computer is aligned, the processing speed is the fastest. The so-called alignment means that the memory address of the index data is exactly a multiple of its size. The int32_t type is 4 bytes, so the compiler will try to make its address a multiple of 4.

 

The former is called the Big-end byte sequence, and the latter is called the small-end byte sequence. Currently, the Intel x86 CPU used in Mac adopts a small byte sequence, and the arm cpu used in iPhone also applies. The PowerPC processor used in earlier Mac adopts the large-end byte sequence. In general, we usually see that different bytes are used in different flags. If the data is read in an incorrect byte order, a disordered and meaningless number is obtained. Therefore, it is important to clarify the byte order.

 

In fact, there is at least another kind of byte order: Intermediate byte order! In some earlier and rare architectures, the forward and backward order are not used, but a strange mixed order is used. For example, the integer 305 419 896, it will be written as {0x34,0x12, 0x78,0x56 }. it is precisely because the storage of the string "UNIX" on some older systems is expressed as "NUXI", so the problem of distinguishing the byte order is sometimes referred to as "NUXI problem ".

 

 

 

 

 

Reference: amazing iPhone cool development-seven first-line experts programming and design examples

Related Article

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.