Linux – Netcat UDP File Transfer Between Two Servers Times Out

linuxnetcatudp

I'm testing file transfer speeds between two Red Hat servers that are connected to the same switch within the data center and I decided to use netcat to eliminate protocol overhead as much as possible.

Testing in TCP mode went well and I was wondering how UDP might fare.

On my receiving (client) end, I ran this:

nc -u -l 11225 -v > myfile.out

And then on the sending (server) end I ran the following:

cat myfile.out | nc -u myserver.foo.zzz.com 11225 -v

The file I'm testing with is 38 GB but the transfer seems to stop at around 15 GB (one time at 14.9, another at 15.6).

I've tested by adding a "-w 5000" just in case it's timing out but no joy. Adding the -v doesn't show anything except acknowledging that the connection occurred. No errors.

So – any suggestions as to why would the transfer cease?

Best Answer

What you are seeing is not a time out. What you are seeing is the result of using the wrong protocol for the purpose.

TCP will perform flow control, which means it will adjust the transmission speed to the capacity of network and receiver. Additionally TCP will retransmit lost packets.

UDP does neither of those. The nc command you used will transmit packets as quickly as it can read the from disk and push them onto the network interface. If the network or the receiving end cannot keep up, it will just keep going at the same speed, and it will send data only once.

If you see only half the data arriving on the other end, it probably means the sending machine is capable of sending the data twice as fast as the rest of the system can handle it.

If you look carefully on the file on the receiving end, you should find that it does not contain just the first half of the original file. Rather you can expect to find fragments from all over the original file.