在Java中,如何处理大于最大UDP数据负载的UDP消息?

发布于 2024-12-10 14:50:26 字数 564 浏览 0 评论 0原文

我读了这个关于我遇到的错误的问题 我了解到 UDP 数据负载不能超过 64k。我读过的建议是使用 TCP,但在这种特殊情况下这不是一个选项。我正在与通过 UDP 传输数据的外部系统连接,但目前我无法访问该外部系统,因此我正在模拟它。

在某些情况下,我的数据消息超过 1,400,000 字节,并且要求使用 UDP 协议。我无法更改协议(我更愿意使用 TCP 或基于 UDP 的可靠协议)。相反,我必须找到一种方法,通过 UDP 将大型有效负载从测试应用程序传输到我正在构建的系统中,并在我正在构建的系统中读取这些大型有效负载进行处理。我也不必担心丢失的数据包 - 如果我没有收到数据报,我也不在乎 - 只需等待下一个有效负载到达即可。如果它不完整或丢失,请将其全部扔掉并继续等待。我也不提前知道数据报的大小(范围从几百字节到 1,400,000+ 字节)。

我已经将发送和接收缓冲区大小设置得足够大,但这还不够。我还能做什么?

I read this question about the error that I'm getting and I learned that UDP data payloads can't be more than 64k. The suggestions that I've read are to use TCP, but that is not an option in this particular case. I am interfacing with an external system that is transmitting data over UDP, but I don't have access to that external system at this time, so I'm simulating it.

I have data messages that are upwards of 1,400,000 bytes in some instances and it's a requirement that the UDP protocol is used. I am not able to change protocols (I would much rather use TCP or a reliable protocol build on UDP). Instead, I have to find a way to transmit large payloads over UDP from a test application into the system that I am building and to read those large payloads in the system that I'm building for processing. I don't have to worry about dropped packets, either - if I don't get the datagram, I don't care - just wait for the next payload to arrive. If it's incomplete or missing, just throw it all away and continue waiting. I also don't know the size of the datagram in advance (they range of a few hundred bytes to 1,400,000+ bytes.

I've already set my send and receive buffer sizes large enough, but that's not sufficient. What else can I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

李不 2024-12-17 14:50:27

这是一个要求...

因此,该要求也应该决定打包技术。您需要有关外部系统及其协议的更多信息。请注意,最大 IPv4 UDP 有效负载为 65535-28 字节,最大实际有效负载一旦路由器介入,则为 1500 字节。

It's a requirement ...

The requirement should also therefore dictate the packetization technique. You need more information about the external system and its protocol. Note that the maximum IPv4 UDP payload Is 65535-28 bytes, and the maximum practical payload is < 1500 bytes once a router gets involved.

逐鹿 2024-12-17 14:50:26

UDP 数据包有一个 16 位长度的字段。与Java无关。它们不能更大,就这样。如果您正在交谈的服务器是不可变的,那么您就只能局限于可以装入数据包的内容。

如果您可以更改服务器并因此更改协议,您或多或少可以为自己重新实现 TCP。由于 UDP 被定义为不可靠,因此您需要完整的重传机制来应对网络中某处丢失的数据包。因此,您必须将“消息”拆分为块,发送块,并制定一个用于请求重传丢失块的协议。

UDP packets have a 16 bit length field. It's nothing to do with Java. They cannot be bigger, period. If the server you are talking to is immutable, you are stuck with what you can fit into a packet.

If you can change the server and thus the protocol, you can more or less reimplement TCP for yourself. Since UDP is defined to be unreliable, you need the full retransmission mechanism to cope with packets that are dropped in the network somewhere. So, you have to split the 'message' into chunks, send the chunks, and have a protocol for requesting retransmission of lost chunks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文