如何增加 UDP 的最大数据包大小?
我通常发送 3 到 15 KB 的数据包,但有时我需要发送大约 0.8-0.9 MB 的大数据包。在这种情况下,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. In that case the UDP socket will stop because there is probably some limit on a single packet size.
How can I increase this limit so I can send large packets?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UDP数据包头中的
length
字段的宽度只有16位;您不能拥有大于 65,535 字节的单个 UDP 数据包(也包括标头,因此实际上限制为 65,527 字节;由于 IP 还有其他限制,它可能甚至更低)。The
length
field in the UDP packet header is only 16 bits in width; 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).请注意,大于 MTU 的 UDP 数据包(在主机之间的每个希望)将被 IP 分割。如果其中一个部分丢失,则整个 UDP 数据包将被丢弃。没有重传。
在本地 LAN 上,流量较低时您可能不会注意到差异,但在任何不太理想的情况下,这可能会对性能造成巨大影响。
我认为最好的方法是:
note that UDP packets bigger than the MTU's (at every hope between your hosts) will be split by IP. If a single one of these parts is lost, the whole UDP packet will be discarded. 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.
I think it would be much better to either:
尽管第 4 层标头中的字段大小有限制,但可以使用大于 64K 的数据包。请参阅IPv6 Jumbograms。
It is possible to use packets >64K, despite the size limitation of fields in the layer-4 headers. See IPv6 Jumbograms.