Fundamentals 8 min read

Understanding TCP and UDP: Principles, Differences, and Communication Processes

This article provides a comprehensive overview of TCP and UDP, explaining their roles in the transport layer, key differences, the three‑way handshake, data transmission mechanisms, four‑way termination, and the characteristics of UDP, illustrated with diagrams for clarity.

Architecture Digest
Architecture Digest
Architecture Digest
Understanding TCP and UDP: Principles, Differences, and Communication Processes

Recently I revisited the principles and differences of TCP and UDP and made a concise summary.

1. Role

Both TCP and UDP operate at the transport layer to enable data exchange between programs, handling various data types such as files, video streams, and images.

2. Differences

TCP is connection‑oriented, while UDP is connection‑less.

TCP offers stable and reliable data transmission, suitable for scenarios requiring high communication quality such as file transfer, email, and web browsing.

UDP provides fast transmission but may lose packets, making it ideal for real‑time applications that can tolerate occasional loss, such as DNS queries, voice calls, video streaming, and tunnel networks like VXLAN.

Analogously, UDP is like sending a letter without knowing if it arrives, whereas TCP is like a phone call with immediate feedback.

3. TCP Communication Process

TCP ensures reliable communication through three steps: three‑way handshake, data transmission acknowledgment, and four‑way termination.

Three‑Way Handshake

When a client initiates a connection, it sends a SYN packet; the server replies with SYN‑ACK; the client responds with ACK, establishing the connection.

Why Three Handshakes?

The three‑handshake design prevents stale SYN packets from causing erroneous connections, ensuring both sides agree on the connection state even in unreliable networks.

Data Transmission

TCP splits data into segments, assigns sequence numbers, and uses a send buffer. The receiver acknowledges each segment with an ACK containing the next expected sequence number, handling loss, ordering, and flow control.

4. Four‑Way Termination

Either side can initiate connection closure. The client sends FIN, the server ACKs, then the server sends its own FIN, the client ACKs, and after a timeout the connection fully closes, ensuring both sides have received the final acknowledgments.

5. UDP Protocol

UDP is connection‑less; it simply encapsulates data into packets and sends them without establishing state, resulting in low overhead and high speed but no guarantee of delivery or ordering.

The main differences can be summarized as: TCP provides reliable, ordered delivery for high‑quality communication, while UDP offers fast, best‑effort delivery for latency‑sensitive scenarios, and is also used for tunneling technologies like VXLAN.

TCPnetwork protocolsData TransmissionUDPhandshake
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.