简体   繁体   English

如何增加UDP的最大数据包大小?

[英]How to increase a maximum packet size for UDP?

I am usually sending packets that range from 3 to 15 KB but from time to time I need to send a large packet which is about 0.8-0.9 MB. 我通常发送的数据包的大小为3到15 KB,但有时我需要发送一个大的数据包,大约为0.8-0.9 MB。 In that case the UDP socket will stop because there is probably some limit on a single packet size. 在那种情况下,UDP套接字将停止,因为单个数据包的大小可能存在一些限制。

How can I increase this limit so I can send large packets? 如何增加此限制,以便可以发送大数据包?

The length field in the UDP packet header is only 16 bits in width; UDP数据包报头中的length字段只有16位宽度。 you can't have a single UDP packet larger than 65,535 bytes (that includes the header, too, so really the limit is 65,527 bytes; it's probably even lower still since IP has other restrictions). 您不能有一个大于65,535字节的UDP数据包(也包括标头,因此实际上限制为65,527字节;由于IP有其他限制,它甚至可能更低)。

note that UDP packets bigger than the MTU's (at every hope between your hosts) will be split by IP. 请注意,大于MTU的UDP数据包(在您的主机之间希望如此)将由IP拆分。 If a single one of these parts is lost, the whole UDP packet will be discarded. 如果这些部分中的一个丢失,整个UDP数据包将被丢弃。 There's no retransmission. 没有重传。

On a local LAN, with low traffic you might not note the difference, but in any not-so-ideal situation, it could be a huge performance hit. 在本地LAN上,通信量较低时,您可能不会注意到其中的区别,但是在任何不太理想的情况下,这可能会严重影响性能。

I think it would be much better to either: 我认为这会更好:

  • use TCP for anything bigger than a few KB's 将TCP用于大于几KB的任何内容
  • split your messages (you'll find pretty soon you're reinventing TCP) 拆分消息(很快就会发现您正在重新发明TCP)
  • use some other well-tested protocol on top of UDP. 在UDP之上使用其他经过良好测试的协议。 One example is UDT 一个例子是UDT

It is possible to use packets >64K, despite the size limitation of fields in the layer-4 headers. 尽管第4层标头中字段的大小有限制, 可以使用> 64K的数据包。 See IPv6 Jumbograms . 请参阅IPv6 Jumbograms

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM