Why I can't get all UDP packets?

Posted by Jack on Stack Overflow See other posts from Stack Overflow or by Jack
Published on 2010-03-08T16:45:34Z Indexed on 2010/04/06 22:13 UTC
Read the original article Hit count: 208

Filed under:
|
|
|

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.

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

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?

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.

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

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) { }
}

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

Any more idea? UDP buffer problems???

© Stack Overflow or respective owner

Related posts about udp

Related posts about socket