Text messaging: why TCP fits
When you send a text like “I’m running late, be there in ten”, the receiver must get exactly what you typed — no missing words, no reordering. TCP provides:- Reliable delivery (retransmits lost data),
- In-order delivery (reassembles packets using sequence numbers),
- Flow and congestion control (keeps the network stable).

Connection setup: TCP three-way handshake
Before application data flows, TCP performs a three-way handshake:- Client sends SYN (request to open connection).
- Server replies with SYN-ACK (acknowledges request).
- Client sends ACK (completes handshake).

Packetization, ordering, and retransmission
Once the connection is established, TCP breaks data into segments, assigns sequence numbers, and handles:- Missing packets: the receiver detects gaps and triggers retransmission.
- Out-of-order arrivals: TCP reorders packets before handing data to the application.

Real-time audio/video: why UDP is usually preferred
Voice and video calls stream many small packets continuously. For real-time media, timeliness matters more than recovering every lost packet. Using TCP introduces two key problems for live streams:- Head-of-line blocking: later packets wait for retransmissions of earlier lost packets, causing pauses.
- TCP congestion response: loss causes reduced send rates, increasing latency and making audio/video choppy.

What UDP provides — and what the application layer adds
UDP itself is minimal: no handshake, no guaranteed delivery, no automatic retransmission, and no enforced ordering. Real-time apps build reliability and timing handling in the application layer, typically using protocols such as RTP/SRTP. Application-layer techniques include:- Sequence numbers and timestamps (detect lost/late packets and reorder),
- Jitter buffers (smooth variable arrival times),
- Selective retransmission or forward error correction (for non-real-time-critical parts),
- Dropping packets that arrive too late to be useful.

Use both protocols where appropriate
Many apps keep both connection types simultaneously:- Media (real-time voice/video): UDP + RTP/SRTP, optimized for low latency.
- Text, file transfer, or control messages: TCP or TLS over TCP (HTTP/2) for reliability and ordering.
Security is orthogonal to TCP vs UDP
Neither transport encrypts payloads by default. Security (encryption, authentication, integrity) must be added at a higher layer:- Use TLS to secure TCP streams.
- Use SRTP to secure RTP over UDP.
- Use end-to-end application protocols (e.g., Signal Protocol) for message-level encryption.
Neither TCP nor UDP provides encryption by default. Use TLS, SRTP, or an application-level protocol (e.g., Signal Protocol) to secure transported data.

Quick comparison
Summary
- Use TCP when you need reliable, ordered delivery (e.g., text, files, transactional data).
- Use UDP when low latency and timeliness trump perfect delivery (e.g., real-time voice/video), and rely on RTP/SRTP or application logic for sequencing, jitter management, and security.
- Encryption and authentication are implemented at higher layers — choose TLS, SRTP, or application-level end-to-end protocols as required.
Links and references
- VoIP — Wikipedia
- RTP — Real-time Transport Protocol
- SRTP — Secure Real-time Transport Protocol
- TLS — Transport Layer Security
- Signal Protocol