在Java中,如何处理大于最大UDP数据有效负载的UDP消息? [英] In Java, how do I deal with UDP messages that are greater than the maximum UDP data payload?

查看:472
本文介绍了在Java中,如何处理大于最大UDP数据有效负载的UDP消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了有关我所犯错误的问题,我了解到UDP数据有效载荷不能超过64k.我读过的建议是使用TCP,但是在这种特殊情况下这不是一个选择.我正在与正在通过UDP传输数据的外部系统进行交互,但是目前我无法访问该外部系统,因此我正在对其进行仿真.

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.

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

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?

推荐答案

UDP数据包具有16位长度的字段.与Java无关.他们不能更大,时期.如果您要与之通信的服务器是不可变的,那么您将无法容纳包中的内容.

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.

如果您可以更改服务器,从而更改协议,则可以自己或多或少地重新实现TCP.由于UDP被定义为不可靠的,因此您需要完整的重传机制来应对网络中某处丢弃的数据包.因此,您必须将消息"拆分为多个块,然后发送这些块,并具有用于请求重新传输丢失的块的协议.

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.

这篇关于在Java中,如何处理大于最大UDP数据有效负载的UDP消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆