The maximum size of a UDP package

Source: Internet
Author: User

The maximum size of a UDP package can be larger. 1. When programming with UDP, we are most likely to think of the problem of how many bytes are sent at a time? Of course, there is no unique answer. The answer is different from the requirements of different systems. Here I only analyze the situation of sending chat messages like ICQ, in other cases, you may also get some help: First, we know that TCP/IP is generally considered a layer-4 protocol system, including the link layer, network layer, transport layer, and application layer. UDP belongs to the transport layer. Next we can see from the next step: the length of the Ethernet data frame must be between-bytes, which is determined by the physical characteristics of the Ethernet. this 1500 byte is called 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 IP datagram data zone length is up to 1480 bytes. the 1480 byte is used to put TCP packet segments or U Because of the first 8 bytes of the UDP datagram, the maximum length of the UDP datagram data zone is 1472 bytes. The 1472 bytes are the available bytes. :) What happens when the UDP data we send is 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 ). divides the datagram into several slices so that each segment is smaller than MTU. the receiver's IP layer needs to reorganize the datagram. in this way, we will do more things. 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 datagram. the entire UDP datagram is discarded. Therefore, in a common LAN environment, it is recommended that UDP data be controlled 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 machines to adjust the MTU value, enable the datagram to reach the destination smoothly, and then perform many unnecessary operations. since the standard MTU value on the Internet is 576 bytes, we recommend that you perform UDP programming on the Internet. we recommend that you set the UDP data length to within 548 bytes (576-8-20. (ps: This sentence seems to be a problem. In the first volume of unix network programming, the ipv4 protocol specifies that the minimum size of the ip layer's reorganization buffer is 576! Therefore, we recommend that the udp packet size not exceed this value, instead of the standard internet MTU is 576 !)

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.