为什么我无法获取所有 UDP 数据包? [英] Why I can't get all UDP packets?

查看:34
本文介绍了为什么我无法获取所有 UDP 数据包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序使用 UdpClient 尝试接收来自 27 个主机的 27 个响应.响应的大小为 10KB.我的宽带传入带宽是 150KB/s.

My program use UdpClient to try to receive 27 responses from 27 hosts. The size of the response is 10KB. My broadband incoming bandwidth is 150KB/s.

这 27 个响应几乎同时从主机发送,每 10 秒发送一次.

The 27 responses are sent from the hosts almost at the same time and for every 10 secs.

但是,我每次只能收到 8 - 17 个回复.我可以收到的响应数量非常动态,但在范围内.

However, I can only receive 8 - 17 responses each time. The number of responses that I can receive is quite dynamic but within the range.

谁能告诉我为什么?为什么我不能全部收到?

Can anyone tell me why? why can't I receive all?

我知道 UDP 不可靠.但我尝试同时收到 5 - 10 条回复,它奏效了.我想网络链接还不错.

I understand UDP is not reliable. but I tried receiving 5 - 10 responses at the same time, it worked. I guess the network links are not so bad.

代码非常简单.在 27 台主机上,我只使用 UdpClient 将 10KB 发送到我的机器.

The code is very simple. ON the 27 hosts, I just use UdpClient to send 10KB to my machine.

在我的机器上,我有一个 UdpClient 接收数据报.每次获取数据时,我都会创建一个线程来处理它(基本上处理它意味着只是打印出我收到了 10KB",但它在一个线程中运行).

On my machine, I have one UdpClient receive datagrams. Each time I get a data, I create a thread to handle it (basically handling it means just print out "I received 10KB", but it runs in a thread).

listener = new UDPListener(Port);
listener.Start();
while (true) {
    try {
        UDPContext context = listener.Accept();
        ThreadPool.QueueUserWorkItem(new WaitCallback(HandleMessage), context);

    } catch (Exception) { }
}

如果我将响应的大小减少到 3KB,情况会好得多,大约可以收到 25 个响应.

If I reduce the size of the response down to 3KB, the case gets much better that roughly 25 responses can be received.

还有什么想法吗?UDP 缓冲区问题???

Any more idea? UDP buffer problems???

推荐答案

正如您自己所说,UDP 不可靠.所以数据包很可能会被丢弃在某个地方.

As you said yourself, UDP is not reliable. So chances are packets are dropped somewhere.

请注意,交换机/路由器/网卡过载造成的丢包与不良链接造成的丢包一样多.如果有人同时"向您发送 27 个 10Kb 响应.很可能是您的网卡或附近交换机的缓冲区已满,并且数据包被丢弃.

Note that packet drop is caused just as much by overloaded switches/routers/network cards as by bad links. If someone sends you 27 10Kb responses "simultaneously". it might very well be that the buffers of your network card, or a nearby switch are full, and packets get dropped.

除非你有一些代码要展示,否则可能没有什么可说的.

Until you have some code to show, there's probably not much else to say.

这篇关于为什么我无法获取所有 UDP 数据包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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