简体   繁体   English

UDP sendto()和recvfrom()最大缓冲区大小

[英]UDP sendto() and recvfrom() max buffer size

I understand that the default max buffer size I can use with these functions is 65507 (5535 - IPv4 header - UDP header). 我知道我可以使用这些函数的默认最大缓冲区大小是65507(5535 - IPv4标头 - UDP标头)。 However, is there a way to change this? 但是,有没有办法改变这个? I need to be able send a larger buffer ~66000 bytes. 我需要能够发送更大的缓冲区~66000字节。 I tried using the setsockopt() function, but it didn't seem to work. 我尝试使用setsockopt()函数,但似乎没有用。

Thanks! 谢谢!

No. 没有。

UDP only provides a datagram as the data part of an IP packet, an IP packet has a 16 bit length field thus limiting the data to 2^16 bytes including the headers, or 65507 bytes for the UDP data part(assuming no ipv4 options), there's no way to handle larger packets with UDP besides splitting them up in several packets and handle the reassembly etc. yourself. UDP仅提供数据报作为IP数据包的数据部分,IP数据包具有16位长度字段,因此将数据限制为包括报头的2 ^ 16字节,或UDP数据部分的65507字节(假设没有ipv4选项) ,除了将它们分成几个数据包并自己处理重组等之外,没有办法用UDP处理更大的数据包。

Also it is quite likely to loose "big" UDP packets along the way, because the wrapping IP packet might be fragmented due to MTU limitations. 此外,它很可能在此过程中丢失“大”UDP数据包,因为包装IP数据包可能由于MTU限制而被分段。 Each of the fragments might get lost and there is no recovery mechanism in UDP. 每个片段都可能丢失,UDP中没有恢复机制。 So while the theoretical limit for UDP payload is approx. 因此,虽然UDP有效载荷的理论限制是大约。 64kB the practical limit is around 1kB. 64kB的实际限制大约是1kB。

The UDP specification gives you 16bits in the UDP header for the packet size, that means you cannot send more than 65k at once. UDP规范在UDP报头中为您提供16位数据包大小,这意味着您不能一次发送超过65k。 You cannot change this. 你无法改变这一点。

You have to split up your data into multiple packets. 您必须将数据拆分为多个数据包。 Using TCP instead of UDP will make the thing much simpler, since completeness and receiving order are guaranteed. 使用TCP而不是UDP将使事情变得更简单,因为完整性和接收顺序是有保证的。

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

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