Outlets: sometimes (rarely) packets are lost during reception

I use Socket to receive data from udp multicast. The code is trivial:

 s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); .... while (true) { int count = 0; try { count = socket.Receive(byteArray); } catch (Exception e) { Console.WriteLine(e.Message); return; } if (count > 0) { OnNewMessage(new NewMessageEventArgs(byteArray, count)); } } 

The problem is that sometimes I lose packets. Not too often, ~ once every 2 minutes.

I am sure that the package was received because I see it in another C ++ program running on the same computer and configured to receive the same packages.

Why can't my program catch packages that others can use? Why am I losing packages? Is it possible that the computer is too slow (or too busy) to receive packets?

I get about 2,000 packets per second and using the Xeon E3 processor, which should be more than what I think ...

+2
source share
2 answers

If you are absolutely sure that the packet arrives (and: I must emphasize that this is not guaranteed when using UDP, and 1 packet drops out every two months at 2000 packets per second - it is better to receive than you probably hope, even for two adjacent machines ), this probably means that the receive buffer is filling up in short moments. Try increasing ReceiveBufferSize .

+3
source

Not if this is your case, but sometimes you can receive more packets in a single byte array socket.Receive (byteArray). This is due to socket optimization. Check if this is your case, and check your parsing methods.

0
source

Source: https://habr.com/ru/post/911477/


All Articles