[Avg. reading time: 6 minutes]

TCP & UDP

  • Transmission Control Protocol
  • User Datagram Protocol

TCP and UDP are transport protocols. Their only job is to decide how data moves across the network.

Common IoT problems

  • Sensors generate data continuously
  • Networks are unreliable
  • Devices are constrained
  • Some data losses are acceptable and some are not.

UDP

  • Sends data without confirmation
  • No retries
  • No ordering
  • No connection
  • Very low overhead

UDP Usecases in IOT

  • Battery powered devices
  • High frequency telemetry
  • Small payloads
  • Occasional loss is acceptable
  • Speed matters more than accuracy

Typical IoT usage

  • CoAP
  • Device discovery
  • Heartbeats
  • Periodic measurements of Environmental sampling

Example

Smart street lighting

  • Each lamp sends a heartbeat every 5 to 10 seconds
  • Payload: device_id, status, battery, signal strength
  • If ā€˜n’ heartbeats are missed, mark lamp as offline
  • Losing one packet changes nothing.

Vehicle Telematics

  • Fleet vehicles send location and health pings
  • One ping every few seconds
  • Next ping overrides the previous

TCP

  • Confirms delivery
  • Retries lost data
  • Preserves order
  • Maintains a connection
  • Higher overhead

TCP use cases in IoT

  • Data must not be lost
  • Order matters
  • Sessions last minutes or hours

Typical IoT usage

  • MQTT
  • HTTP
  • HTTPS
  • TLS secured pipelines

With MQTT

  • Ordered messages
  • Delivery guarantees using QoS
  • Persistent sessions
  • Broker side buffering
  • Fan out to many subscribers

UDP vs TCP

QuestionUDPTCP
Is delivery guaranteedNoYes
Is ordering preservedNoYes
Is it lightweightYesNo
Does MQTT use itNoYes
Does CoAP use itYesNo
Best for battery devicesYesSometimes
Best for critical dataNoYes
          SENSOR
            |
            |
     -----------------
     |               |
   UDP Path         TCP Path
     |               |
 No confirmation   Confirmed delivery
 No retry          Retry on failure
 Possible loss     Ordered messages
     |               |
   CoAP           MQTT Broker
                     |
               Persistent sessions
                     |
                 Cloud Applications
````<span id='footer-class'>Ver 6.0.5</span>
<footer id="last-change">Last change: 2026-02-05</footer>````