当前位置:网站首页>面试突击:为什么 TCP 需要 3 次握手?
面试突击:为什么 TCP 需要 3 次握手?
2022-07-25 15:41:00 【51CTO】
TCP 三次握手是一道经典的面试题,它是指 TCP 在传递数据之前,需要进行 3 次交互才能正式建立起连接,并进行数据传递。TCP 之所以需要 3 次握手是因为 TCP 双方都是全双工的。所谓全双工指的是,TCP 任何一端既是发送数据方,又是接收数据方,因此这就要求 TCP 通讯双方既要保证自己的发送能力,又要保证自己的接收能力才行。这就好像打电话时,通讯双方都要保证自己能话筒(传递声音)和耳机(接收声音)都是正常的才行,这样才能进行有效的交流,通常打电话时,都是这样开头的:
- 我:喂,能听到我说话吗?
- 对方:能听到你说话,你能听到我说话吗?
- 我:能听到你说话,那我们就来聊正事吧。
TCP 三次握手也是相同的道理,3 次握手证明的能力详情如下:

TCP 三次握手流程
TCP 三次握手流程如下:
- 客户端发送 SYN 给服务器端,表示希望建立连接;
- 服务器端接收到消息之后,回应一个 SYN 和 ACK(确认应答)给客户端;
- 客户端收到服务器端的 SYN 报文之后,回应一个 ACK 报文。
具体执行流程如下图所示:

总结
TCP 之所以需要 3 次握手,是因为 TCP 通讯双方都是全双工的,所以要经过 3 次交互才能确认双方的发送能力和接收能力,并且 TCP 握手必须是 3 次,如果是 2 次握手,不能证明服务器端的发送能力和客户端的接收能力;也不能是 4 次握手,因为 3 次已经能证明的事情,再交互握手 1 次完全没有必要。
边栏推荐
- Cf566a greed + dictionary tree
- Redis distributed lock, it's really impossible without it
- Qtime definition (manual waste utilization is simple and beautiful)
- Understanding the difference between wait() and sleep()
- Matlab simulation of BPSK modulation system (1)
- Pytoch learning notes -- Summary of common functions 2
- LeetCode - 641 设计循环双端队列(设计)*
- Gary marcus: learning a language is more difficult than you think
- Leetcode - 225 implements stack with queue
- MySQL教程67-使用DISTINCT过滤重复数据
猜你喜欢

【服务器数据恢复】HP EVA服务器存储意外断电导致RAID信息丢失的数据恢复案例

报表工具的二次革命

用GaussDB(for Redis)存画像,推荐业务轻松降本60%

Idea - click the file code to automatically synchronize with the directory

Pytoch learning notes -- Summary of common functions 3

谷歌博客:采用多重游戏决策Transformer训练通用智能体

Why is preparestatement better and safer?

Ml image depth learning and convolution neural network

LeetCode - 225 用队列实现栈

How matlab produces random complex sequences
随机推荐
Understanding the difference between wait() and sleep()
LeetCode - 677 键值映射(设计)*
How to solve cross domain problems
HDD Hangzhou station · harmonyos technical experts share the features of Huawei deveco studio
ML - Speech - traditional speech model
How Google cloud disk is associated with Google colab
十字链表的存储结构
Matlab randInt, matlab randInt function usage "recommended collection"
30 lines write the concurrency tool class yourself (semaphore, cyclicbarrier, countdownlatch)
Storage structure of cross linked list
Redis分布式锁,没它真不行
Reasons for data format conversion when matlab reads the displayed image
How to realize page inclusion
如何实现页面包含
Pytorch学习笔记-Advanced_CNN(Using Inception_Module)实现Mnist数据集分类-(注释及结果)
Zhaoqi Kechuang high-quality overseas returnee talent entrepreneurship and innovation service platform, online live broadcast Roadshow
兆骑科创海内外高层次创新创业人才服务平台,双创成果转化平台
Dpdk packet receiving and sending problem case: non packet receiving problem location triggered by mismatched packet sending and receiving function
推荐系统-协同过滤在Spark中的实现
Leetcode - 380 o (1) time to insert, delete and get random elements (design hash table + array)