Design network code and network code
The Protocol itself is a custom protocol for transportation and location over UDP. There are many reasons why I decided to use the custom protocol. First, the current task looks 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 tries its best to conceal the reliability and uncertainty of its underlying network.
UDP exposes many uncertainties. It uses a checksum to ensure that a corrupted 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 data will be received in disorder.
The reason for using UDP is that UDP uses fewer resources and provides better performance. In essence, TCP is based on connections. Therefore, each remote device to communicate with must establish and maintain connections. If you plan to support a large number of devices, the overhead will be very high. In addition, TCP may also be slower, such as packet loss. At this time, TCP will try to fix the problem, but it takes time to recover it. 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.