Transport layer protocol UDP

1. UDP protocol segment format

  1. Source Port Number : This field is a 16-bit field that represents the port number of the sending application.

  2. Destination port number : This field is similar to the source port. It is also a 16-bit field that represents the port number of the receiving application.

  3. Length : This field indicates the total length of the UDP data message, including the UDP header and data part. It is a 16-bit field with a minimum value of 8 bytes (the size of the UDP header) and a maximum value of 65535 bytes, which means the maximum length of a UDP datagram is 64 kb.

  4. Checksum : This field is used to verify the integrity of UDP data messages. The checksum is a 16-bit field that is calculated by the sender and used by the receiver for verification. The calculation of the checksum involves the entire UDP data message (including the UDP header and data part) in order to detect any data changes or errors in transmission.

  5. Data : This field stores a complete application layer datagram. Its length can be deduced from the length field. The data part can be empty or contain data of any length.

2. Let’s talk about the characteristics of UDP again

Connectionless : UDP is a connectionless protocol. This means that no connection needs to be established between the sender and receiver before data is transferred. Each UDP data message is independent and there is no correlation between them. Therefore, UDP communication has low latency and less overhead.

Unreliable : UDP does not provide reliability in data transmission. It has no retransmission mechanism or error recovery mechanism, nor does it handle loss, duplication, and disorder of data packets. If UDP is used for data transmission, packet loss, lost or damaged data may occur. Therefore, UDP is mainly suitable for applications that have high real-time requirements but relatively low data reliability requirements, such as audio and video transmission and real-time games.

Datagram-oriented : UDP is a datagram-oriented protocol. Each UDP packet is considered an independent data message, has its own start address and destination address, and is independent of other data messages. UDP does not split or reassemble the data stream, maintaining the integrity of the data packets. If the sender sends 100 bytes at a time, the receiver must also receive 100 bytes at a time; instead of receiving 10 times in a loop, receiving 10 bytes each time.

Full duplex : UDP socket can both read and write, supporting two-way communication.

UDP buffer : UDP only has a receive buffer and no send buffer. UDP has no real send buffer. The sent data will be directly handed over to the kernel, which will pass the data to the network layer protocol for subsequent transmission actions; UDP has a receive buffer, but this receive buffer cannot guarantee the order of received UDP packets and the order of sent UDP packets. Consistent; if the buffer is full, incoming UDP data will be discarded.

Size limitation : There is a maximum length of 16 bits in the UDP protocol header. In other words, the maximum length of data that can be transmitted by a UDP is 64KB (including UDP header and data)

3. Preview of next issue

Since UDP is unreliable and has a limited length, what should we do if reliable transmission is required and the data length is greater than 64K? Here we need to introduce another more powerful transport layer protocol, TCP. We will introduce TCP in detail in the next issue. Stay tuned!

Guess you like

Origin blog.csdn.net/LEE180501/article/details/133235431