The maximum number of UDP data packets sent at a time is good.

Source: Internet
Author: User

Article Source: http://blog.163.com/yuyi_vc/blog/static/170371753201152901727665/

During UDP programming, the most common question is how many bytes are sent at a time?

Of course, there is no unique answer. The answer to this question varies with systems and requirements, here, I will only analyze the situation of sending chat messages like ICQ. For other cases, you may also get some help:

First, we know that TCP/IP is generally considered as a layer-4 protocol system, including the link layer, network layer, transport layer, and application layer.

UDP belongs to the transport layer. Let's look at it from the next step:

The length of an Ethernet data frame must be between-bytes.Physical Features. This 1500 byte is formed as the MTU (maximum transmission unit) of the link layer ). However, this does not mean that the link layer length is limited to 1500 bytes. In fact, this MTU refers to the data area of the link layer. It does not include 18 bytes at the beginning and end of the link layer. Therefore, in fact, this 1500 byte is the length limit of network layer IP datagram. Because the IP datagram header is 20 bytes, the maximum length of the IP datagram data zone is 1480 bytes. The 1480 byte is used to store TCP packet segments or UDP datagram packets from UDP. Because the first 8 bytes of the UDP data packet, the maximum length of the UDP data packet is 1472 bytes. This 1472 byte is the number of bytes that we can use. :)

What happens when we send UDP data greater than 1472?

This means that the IP datagram is greater than 1500 bytes and greater than MTU. In this case, fragmentation is required for the sender's IP layer ). Divide the datagram into several slices so that each segment is smaller than MTU. The receiver's IP layer needs to reorganize the datagram. This will do more, but more seriously, due to the characteristics of UDP, when a piece of data is lost during transmission, it is easy to receive and cannot reorganize the data packet, which will cause the entire UDP datagram to be discarded.

ThereforeCommon LAN environmentNext, we recommend that you control UDP data below 1472 bytes.

When programming the Internet, the MTU may be set to different values on the internet router. If we assume that the MTU is 1500 to send data, and the MTU value of a network passing through is smaller than 1500 bytes, the system will use a series of mechanisms to adjust the MTU value, enable the datagram to reach the destination smoothly, so as to do a lot of unnecessary operations.

In viewThe standard MTU value on the internet is 576 bytes.Therefore, we recommend that you set the UDP data length to 548 bytes (576-8-20) during Internet UDP programming.

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.