【发布时间】:2015-09-04 07:38:51
【问题描述】:
我正在使用 UDP 客户端每秒发送大约 20k 个请求,每个请求的数据
public void startRecieve() throws IOException {
udpSocket = new DatagramSocket(Constant.PORT);
byte[] buffer = new byte[Constant.SIZE];
udpPacket = new DatagramPacket(buffer, buffer.length);
int len;
while (true) {
udpSocket.receive(udpPacket);
len = udpPacket.getLength();
if (len > 0) {
// handing the data using other thread pool
}
}
}
有什么办法可以让UDP服务器丢包率更低?
谢谢。
【问题讨论】:
-
安装光缆并对其进行绝缘以防止噪音,这应该会有所帮助。
-
@andy:- 检查这个:stackoverflow.com/questions/8267271/…
-
@andy:你的(发送和接收)套接字缓冲区大小是多少?两边都调用了 setReceiveBufferSize 和 setSendBufferSize 函数吗?
-
您应该使用现有的 UDP 服务器,处理器随时可用,而不是从头开始构建。其次,UDP不可靠,如果你想要可靠的东西,就选择TCP,想要实时的东西,就选择RTP。但是不要期望通过发布 10 行代码,您会期望用户帮助降低 UDP 错误率。另外,请检查 Rahul 提出的问题,该问题的答案是正确的。