07 — TCP vs UDP

Reliable phone call vs. quick shout.

Estimated 8 minutes.

Two ways to send data.

Once a packet has an IP and a port, the network has to actually deliver it. There are two main ways: TCP and UDP. They sit at the same layer but solve completely different problems.

TCP — the phone call.

TCP is a conversation. The sender and receiver shake hands, agree to talk, and acknowledge every chunk of data. If something goes missing, it's resent. The result is guaranteed, in-order delivery.

UDP — the shout.

UDP just throws the packet onto the network and walks away. No handshake. No acknowledgment. If it arrives, great. If not, it's gone. Faster, leaner — but no safety net.

Side by side on the wire.

TCP costs more round trips. UDP costs nothing extra.

The packet race.

Two lanes — TCP on top, UDP on bottom. Crank the network loss slider. Watch TCP keep delivering (slower) while UDP loses data forever.

Which is slower?

For sending one tiny status update, which protocol has more overhead?

  • TCP
  • UDP
  • Same

Modbus TCP uses TCP.

When reliability matters more than speed, TCP wins. Modbus TCP rides on TCP because losing a register read should never go unnoticed. HTTP, OPC UA client-server, and most SCADA traffic also use TCP.

Real-time motion skips the safety net.

EtherCAT and Profinet IRT don't use UDP — or even IP. They ride directly on raw Ethernet frames with their own EtherType. Other motion-class buses run on UDP. Either way the rule is identical: no handshake, no acknowledgments, no retransmits. If a packet is late, the next one is already on the wire.

Why UDP for motion?

A high-speed motion controller updates 1000 times per second. Why prefer UDP over TCP?

  • UDP is more secure
  • A retransmitted command would arrive too late to matter
  • TCP doesn't support fast networks

The trade-off in one line.

TCP: reliable but slower. UDP: fast but lossy. Pick TCP when correctness matters. Pick UDP when timeliness matters more than completeness.

Stream a temperature reading once a second.

You want to log temperatures from 200 sensors, once per second, to a database. Which transport?

  • TCP — losing a reading matters
  • UDP — speed beats correctness

Both use ports.

TCP and UDP both layer on top of IP and both use ports. So "port 502" is technically TCP port 502 — there's also a separate UDP port 502, completely independent. Always check which one your protocol uses.

One last call.

A protocol needs guaranteed delivery, in-order, but speed is not critical. Which transport?

  • TCP
  • UDP

You can choose the right transport.

  • TCP is reliable, ordered, with acknowledgments. Higher latency.
  • UDP is fast and connectionless. No safety net.
  • Modbus TCP, OPC UA, HTTP → TCP. Real-time motion buses → UDP.
  • Trade-off: correctness vs. timeliness.

Lesson 07 complete.

  • You can describe both transports clearly.
  • You know which industrial protocols use each.
  • You can pick the right one for a new design.