Fundamentals 9 min read

Understanding TCP vs UDP: Handshakes, Data Transfer, and Key Differences

This article explains how TCP and UDP operate at the transport layer, compares their reliability and speed, details the TCP three‑way handshake and four‑way termination processes, and outlines how each protocol handles data segmentation, ordering, and loss.

Architects' Tech Alliance
Architects' Tech Alliance
Architects' Tech Alliance
Understanding TCP vs UDP: Handshakes, Data Transfer, and Key Differences

Role of TCP and UDP

Both TCP and UDP operate at the transport layer to carry application data such as files, video streams, and images.

Key differences

TCP is connection‑oriented and provides reliable, ordered delivery. It is suited for scenarios that require high communication quality, such as file transfer, email, and web browsing.

UDP is connection‑less, prioritizes low latency over reliability, and tolerates occasional packet loss. Typical use cases include DNS queries, voice calls, live video streaming, and tunneling protocols like VXLAN.

TCP communication process

Three‑way handshake

The client initiates a connection with a SYN packet. If the server accepts, it replies with a SYN‑ACK packet. The client then sends an ACK packet, completing the handshake and establishing a reliable channel. This three‑step exchange prevents stale or duplicate connection attempts caused by delayed packets.

Data transmission

Large data blocks are split into multiple segments. TCP assigns a sequence number to each byte, starting at zero, and includes these numbers in segment headers. The receiver acknowledges received data with an ACK containing the next expected sequence number, enabling detection of lost or out‑of‑order packets and supporting retransmission.

Four‑way termination

Either side can initiate closure by sending a FIN packet. The peer acknowledges with an ACK, then sends its own FIN when ready to close. The original side replies with a final ACK. The waiting period after the last ACK ensures that any lost ACKs are retransmitted, guaranteeing a clean shutdown over an unreliable network.

UDP protocol overview

UDP sends datagrams without establishing a connection or tracking state, resulting in minimal processing overhead and low CPU/memory usage. Because UDP provides no guarantees for delivery, ordering, or integrity, it is less reliable than TCP and is best suited for applications tolerant of occasional loss.

Code example

内容转载于网络。本文整理了一下TCP和UDP的原理以及区别,做一个简单的总结。详细内容请参看文章“
计算机网络模型
”简明讲解。
下载
链接:
计算机网络:TCP IP参考模型
面向AI时代的智能无损数据中心网络
RDMA技术专题汇总(1)
RDMA技术专题汇总(2)
RDMA技术专题汇总(3)
RDMA技术专题汇总(4)
RDMA技术专题汇总(5)
1、面向分布式 AI智能网卡低延迟Fabric技术.pdf
2、RDMA参数选择.pdf
3、RDMA技术白皮书(中文版).pdf
4、RDMA技术在数据中心中的应用研究.pdf
5、华为面向AI时代的智能无损数据中心网络.pdf
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

TCPThree-way handshakeData TransmissionUDPFour-way terminationtransport layerNetworking Fundamentals
Architects' Tech Alliance
Written by

Architects' Tech Alliance

Sharing project experiences, insights into cutting-edge architectures, focusing on cloud computing, microservices, big data, hyper-convergence, storage, data protection, artificial intelligence, industry practices and solutions.

0 followers
Reader feedback

How this landed with the community

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.