0
votes

1) I have a program that sends data via UDP from one server to another.

2) Another program receives these, and simply forwards them via UDP to several destinations, via UDP.

3) One of the destinations is localhost.

Data is being received in 2) and being sent to 3) in a constant flow with no break. Yet the application receiving packets in 3) from 2) is receiving intermittently. It will receive data for a 20 seconds, then not receive for a few minutes, and keeps on in a seemingly random fashion.

This SAME code works perfect when receiving the packets externally. Also, if i run a tcpdump -i lo on the port that 3) is listening on, there is in fact a constant flow of data arriving to the port.

I cannot understand where the problem could be?

-Steve

1
well i think the first thing to mention is that udp is meant to be stateless and not a stream. so dropping packets is normal for udp. i would suggest to test your situation on a lan, with all nodes plugged in via ethernet.owen gerig
Show us the receiving code. "few minutes" is forever in networking world.Nikolai Fetissov
I take issue with "dropping packets is normal for udp" @owen. I think it should be "receiving all packets is not guaranteed". Dropping packets for a significant amount of time like Nikolai mentioned is very unusual. Either this is a threading issue or something else is going on.Gray
It could be that the localhost UDP buffers are overflowing @Steve. What sort of volume are we talking about here? How many packets per second?Gray

1 Answers

0
votes

When you are sending data in TCP you don't have to worry about flow control because TCP does it for you - you can send data as quickly as you like and the write method will block if you are sending it too fast.

This isn't the case in UDP, your packet write will be done and return immediately but if you are sending too many packets too quickly it will simply be discarded. This could happen anywhere along the line from your OS, through all the routers and network devices through to the other machine.

You therefore need to have some scheme which limits the flow of packets yourself. To test if this is the problem just pop a sleep in between each send. If you find that sending 1 packet per second or 10 per second, all of them get through then when you remove the sleep you go back to 20 seconds OK and nothing for a few minutes you know its because your flow control is insufficient.