Android - 发送 DatagramSocket 最大缓冲区大小
我有一个通过 UDP 发送数据的应用程序。 我试图找出最大/最佳发送缓冲区大小是多少。 我已经成功发送了 2k 的包裹,但是更大的包裹是一个问题。 我尝试使用 getSendBufferSize 来查看发送缓冲区大小是多少。它返回 110592 字节。 当我尝试发送任何接近它的内容时,我没有收到错误,但数据没有到达服务器。
我如何知道“允许的”发送缓冲区大小是多少?
谢谢。
I have an app that sends data over UDP.
I'm trying to find out what is the max/optimal send buffer size.
I have succeedded sending a 2k package, but bigger packets was a problem.
I tried using getSendBufferSize to see what is the send buffer size. It returned 110592 bytes.
When I try to send anything close to it, I dont get an error, but the data dosent get to the server.
How do I know what is the "allowed" send buffer size?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DatagramPacket 只是基于 UDP 的套接字的包装器,因此适用通常的 UDP 规则。
64 KB 是完整 IP 数据报的理论最大大小,但只能保证路由 576 字节。在任何给定的网络路径上,具有最小最大传输单元的链路将确定实际限制。 (1500 字节,较少的标头是常见的最大值,但无法预测会有多少标头,因此将消息限制在 1400 字节左右是最安全的。)
参考:Java DatagramPacket (UDP) 最大发送/接收缓冲区大小
DatagramPacket is just a wrapper on a UDP based socket, so the usual UDP rules apply.
64 kilobytes is the theoretical maximum size of a complete IP datagram, but only 576 bytes are guaranteed to be routed. On any given network path, the link with the smallest Maximum Transmit Unit will determine the actual limit. (1500 bytes, less headers is the common maximum, but it is impossible to predict how many headers there will be so its safest to limit messages to around 1400 bytes.)
Reference : Java DatagramPacket (UDP) maximum send/recv buffer size
我也遇到过这个错误,对于 DatagramPacket 发送方法的参数“缓冲区”大小,它应该是 65535 - 28 = 65507 字节。
I've also encountered this error, it should be 65535 - 28 = 65507 bytes, for DatagramPacket send method's parameter "buffer" size.