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
  • 1,692
  • 3
  • 17
  • 34
Xsmael
  • 3,282
  • 6
  • 38
  • 57
  • 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

2

In a congested network, yes, UDP will send its packets faster than TCP, this is because TCP takes then congestion into account using a mechanism called congestion control. UDP has no congestion control, so it'll send packets as fast as the local network interface will allow.

So if your first priority is to send the packets, then UDP is the way to go. However if you're also interested in receiving them, that's another matter. Sending UDP packets into a congested network at a high rate will cause it to become only (much) more congested. This will inevitably lead to long delays and packet loss.

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

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. QoS can give you the network equivalent of bus lanes, that allow buses to quickly pass congested roads.

Malt
  • 27,369
  • 9
  • 61
  • 96