1

I have a real-time application (C++ using websockets) that has to communicate through a congested LAN. Because it's realtime, delays can't be tolerated. Will UDP perform better than TCP in this case?

I cannot tolerate packet loss, but can address it through retries if using UDP.

Charlie
  • 2,004
  • 6
  • 20
  • 40
Xsmael
  • 3,624
  • 7
  • 44
  • 60
  • 2
    [UDP vs TCP, how much faster is it?](http://stackoverflow.com/questions/47903/udp-vs-tcp-how-much-faster-is-it) – jhh Mar 18 '17 at 03:51
  • 1
    @MaMadLord Err, no. TCP has selective ACK, and it is TCP that is the streaming protocol. – user207421 Mar 18 '17 at 08:45
  • i wanted to know from some experiences if you had. because for example UDP is not always fast, in certain conditions TCP will be faster than UDP, as pointed out in @JHH answer. however FYI #MaMadLord it's not for streaming or voip, just tiny bytes are being sent in an irregular interval(depending on the user input)... – Xsmael Mar 18 '17 at 15:53
  • 1
    "_...because i cannot tolerate packet loss..._" UDP is a connectionless, best-effort, fire-and-forget protocol that has no guarantees of data delivery or the order in which the datagrams are received. If you need such a thing with UDP, then you must create an application-layer protocol to handle that. TCP, on the other hand, gives you a connection-oriented protocol that guarantees delivery and reordering of out-of-order segments. – Ron Maupin Mar 19 '17 at 17:41
  • @RonMaupin i'm very conscious of all that you said, and was using tcp, for the same conclusion... however I was wandering if UDP, could possibly be faster in the above mentioned conditions. and using some workarounds to solve loss problem. my goal is to recive the data ASAP – Xsmael Mar 19 '17 at 18:21
  • 2
    To get the guarantee of data delivery, you would need to build an application-layer protocol on top of UDP, and that will slow you down because you are going to need things like acknowledgements, sequencing, etc. that is built into TCP. Some people do this. UDP is often used for real-time data, e.g. VoIP, but it does have data loss, and and out-of-order data is dropped as useless. – Ron Maupin Mar 19 '17 at 18:26

1 Answers1

3

In a congested network UDP will send its packets faster than TCP. This is because TCP actively tries to avoid overloading the network using a mechanism called congestion control. UDP has no such mechanism; its send speed is limited only by the resources of the sender.

If your first priority is to just send the packets, then UDP is the way to go. However, your probably also want them to arrive at the other end, which is a separate problem.

Sending UDP packets into a congested network at a high rate will only cause it to become more congested, leading to long delays and packet loss.

The problem here is neither TCP nor UDP - but the congested network. If the road is congested, it doesn't matter whether you're driving a car or a bus, you'll be late either way.

So, it doesn't matter all that much which protocol you choose. To send something quickly over a congested network you need a solution at the network level, possibly some QoS mechanism to prioritize some packets over others. QoS can give you the network equivalent of bus lanes that allow buses to quickly pass congested roads at the expense of other traffic.

Malt
  • 28,965
  • 9
  • 65
  • 105