Master the UDP protocol

Source: Internet
Author: User

Many protocols have been used in network applications. The most famous protocol is the TCP/IP protocol, but this is actually a protocol set, which contains a variety of protocols. There is the UDP protocol. Next we will introduce the UDP protocol, which is a protocol dedicated to accepting data packets. The UDP Protocol is short for the User data Protocol. It is mainly used to support network applications that need to transmit data between computers. Network applications in customer/Server mode, including network video conferencing systems, must use UDP protocol. UDP has been used for many years since its publication. Although its initial Glory has been concealed by some similar protocols, even today, UDP is still a very practical and feasible network transport layer protocol. Like the well-known TCP transmission control protocol, UDP is directly located at the top layer of the IP Internet protocol. According to OSI Open System Interconnection) reference model, both UDP and TCP are transport layer protocols.

The main function of UDP protocol is to compress network data traffic into a datagram. A typical datagram is the unit of transmission of binary data. The first eight bytes of each datagram are used to contain header information, and the remaining bytes are used to contain specific transmitted data.

UDP Header

The UDP header consists of four fields, each of which occupies two bytes, as follows:

Source Port Number

Destination Port Number

Datagram Length

Check Value

The UDP protocol uses the port number to reserve its own data transmission channels for different applications. The UDP and TCP Protocols use this mechanism to support sending and receiving data simultaneously for multiple applications at the same time. The data sender can be a client or server) sends UDP data through the source port, while the data receiver receives data through the target port. Some network applications can only use static ports reserved or registered for them in advance, while other network applications can use unregistered dynamic ports. Because the UDP header uses two bytes to store the port number, the valid range of the port number is from 0 to 65535. Generally, a port number larger than 49151 represents a dynamic port.

The length of a datagram refers to the total number of bytes, including the header and data. Because the header length is fixed, this field is mainly used to calculate the variable-length data part, also known as the data load ). The maximum length of a datagram varies depending on the operating environment. Theoretically, the maximum length of a datagram containing a header is 65535 bytes. However, in some practical applications, the size of data packets is often limited, and sometimes reduced to 8192 bytes.

UDP uses the checksum value in the header to ensure data security. The verification value is calculated by the Data sender using a special algorithm. After it is passed to the receiver, it needs to be re-calculated. If a data packet is tampered with by a third party during transmission or damaged due to line noise or other reasons, the sent data does not match the verification calculation value of the receiver. Therefore, the UDP protocol can detect whether an error occurs. This is different from the TCP protocol, which requires a verification value.

UDPvs. TCP

The main difference between UDP and TCP is that they differ in how to implement reliable information transmission. The TCP protocol includes a special transmission guarantee mechanism. When the data receiver receives the message from the sender, it will automatically send a confirmation message to the sender; the sender continues to transmit other information only after receiving the confirmation message. Otherwise, the sender waits until the confirmation message is received.

Unlike TCP, UDP does not provide a data transmission guarantee mechanism. If a data packet is lost during transmission from the sender to the receiver, the Protocol itself cannot detect or prompt. Therefore, UDP is often called an unreliable transmission protocol.

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.