Prepare some knowledge for the interview.
The original Article is here
User Datagram Protocol (UDP) is a connectionless transport layer protocol in the OSI reference model. It provides a simple and unreliable information transmission service for transactions. Is a simple datagram-oriented transport layer protocol, IETF
RFC 768 is the formal specification of UDP. UDP is basically an interface between the IP protocol and the upper-layer protocol. The applicable ports of UDP protocol run multiple applications on the same device.
Since most network applications run on the same machine, the computer must be able to ensure that software programs on the machine at the destination can obtain data packets from the machine at the source address, and the source computer can receive the correct response. This is done by using the UDP port number. For example, if a workstation wants
When the Domain Name Service System is used on 128.1.123.1, it will give the packet a destination address 128.1.123.1 and insert the destination port number 53 in the UDP header. The source port number identifies the application of the local machine requesting the Domain Name Service. At the same time, you need to specify all the response packets generated by the destination site to this port of the source host. For more information about UDP ports, see related articles.
Unlike TCP, UDP does not provide reliable IP protocol mechanisms, stream control, and error recovery functions. Because UDP is relatively simple, the UDP header contains a few bytes, which consumes less than the TCP load.
UDP is applicable when TCP reliability is not required. For example, when a high-level protocol or application provides error and flow control functions.
UDP is a transport layer protocol and serves many well-known application layer protocols, including Network File System (NFS), Simple Network Management Protocol (SNMP), and Domain Name System (DNS) as well as simple File Transfer System (TFTP), Dynamic Host Configuration Protocol (DHCP), routing information protocol (RIP) and some audio and video streaming services.
(1) protocol structure
Source Port-16 bits. The source port is an optional field. When used, it indicates the sender's port, and it is considered to be a reply port that needs to be addressed if there is no other information. If not, set the value to 0.
Destination Port-16 bits. The destination port is meaningful when the destination address of the Internet is special.
Length-16 bits. The eight-bit length of the User Datagram, including the protocol header and data. The minimum length is 8.
Checksum-16 bits. IP protocol header, UDP protocol header, and data bit, and finally the sum of false information protocol headers filled with 0. If necessary, it can be composed of two octal digits.
Data-contains upper-layer data information.
UDP has the following features:
1. UDP does not establish a connection with the other party before transmitting data, that is, UDP is not connected. Before transmitting data, the sender and receiver exchange information with each other for synchronization between the two parties.
2. UDP does not sort the received data. There is no information about the data sequence in the UDP packet header (such as the serial number used by TCP ), in addition, messages do not necessarily arrive in order, so the receiving end cannot be arranged.
3. UDP does not send a confirmation signal for the received datagram. The sender does not know whether the data is correctly received or resend the data.
4. UDP transfers data faster than TCP, with less system overhead.
5. Due to the lack of congestion control, a network-based mechanism is required to reduce the congestion collapse effect caused by runaway traffic and high-speed UDP traffic load. In other words, because UDP senders cannot detect congestion, network basic devices such as routers using packet queue and discard technology often become an effective tool to reduce excessive UDP traffic. The Datagram congestion control protocol (DCCP) is designed to reduce this potential problem by adding host congestion control in High-Speed UDP streams such as streaming media.
We can see from the above characteristics that UDP provides a connectionless and unreliable data transmission method and is a data delivery service with the best effort.
(2) UDP services and applications
The services provided by UDP are unreliable and connectionless. UDP is suitable for situations where no response is required and only a small amount of data is transmitted at a time. Because the UDP protocol does not need to establish a logical connection during data transmission and does not check the datagram, UDP has good real-time performance and high efficiency. In some cases, network applications of many customer/Server models, including video teleconference systems, must use UDP protocol.
(3) Several features of UDP protocol
(1) UDP is a connectionless protocol. The source end of data transmission does not establish a connection with the terminal. when it wants to transmit data, it simply crawls data from the application, and throw it to the network as quickly as possible. At the sending end, the speed of UDP data transmission is limited only by the speed at which the application generates data, the ability of the computer, and the transmission bandwidth. at the receiving end, UDP puts each message segment in the queue, the application reads a message segment from the queue each time.
(2) Since no connection is established for data transmission, you do not need to maintain the connection status, including the sending and receiving status. Therefore, a server can transmit the same message to multiple clients at the same time.
(3) The title of the UDP information package is very short, with only 8 bytes. The additional overhead of the 20 bytes information package of TCP is very small.
(4) throughput is not adjusted by the congestion control algorithm, but is limited by the data generation rate, transmission bandwidth, source end and terminal host performance of the application software.
Although UDP is an unreliable protocol, it is an ideal protocol for information delivery. For example, report the stock market on the screen, and display aviation information on the screen. UDP is also used to modify the route table in the route information protocol rip (Routing Information Protocol. In these applications, if a message is lost, another new message will be replaced in a few seconds. UDP is widely used in multimedia applications, such as progressive.
RealAudio software developed by networks is a software that transfers pre-recorded or live music to the client in real time over the Internet, the RealAudio audio-on-demand protocol used by the software is the protocol running on UDP, and most Internet telephone software products also run on UDP.
(4) Application of UDP protocol
UDP is an unreliable network protocol. What is the value or necessity of UDP? In fact, in some cases, UDP may become very useful. Because UDP has a speed advantage beyond the reach of TCP. Although various security protection functions are embedded in the TCP protocol, a large amount of system overhead will be occupied during actual execution, and the speed will undoubtedly be seriously affected. In contrast, UDP eliminates the information reliable transfer mechanism and transfers security and sorting functions to upper-layer applications, greatly reducing the execution time and ensuring the speed.
The earliest specification for UDP protocol was rfc768, which was released in 1980. Although it has been a long time, UDP continues to play a role in mainstream applications. Many applications, including video teleconference systems, prove the value of UDP. Compared with reliability, these applications focus more on actual performance. Therefore, in order to achieve better performance (for example, a higher frame refresh rate), certain reliability (for example, meeting quality ). This is the trade-off between UDP and TCP. Based on different environments and features, the two transmission protocols will play a more important role in the future online world.