当前位置:网站首页>面试突击68:为什么 TCP 需要 3 次握手?
面试突击68:为什么 TCP 需要 3 次握手?
2022-07-26 23:31:00 【王磊】
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 次完全没有必要。
参考 & 鸣谢
《码出高效:Java开发手册》
《Offer 来了》
是非审之于己,毁誉听之于人,得失安之于数。
公众号:Java面试真题解析
边栏推荐
猜你喜欢

毕业进入HW,从测试工程师到项目经理,现如今在鹅厂年收入百万,我的给大家的一些建议...

If you want to thoroughly optimize the performance, you must first understand the underlying logic~

OSPF summary (mind map)

C language student information management system can access text files based on arrays

祝大家七夕快乐,邀你源码共读

Dynamically set the height of applet swiper

I wish you a happy Chinese Valentine's day and invite you to read the source code together

OSPF总结(思维导图)

Redis installation and operation (Linux)

com.fasterxml.jackson.databind.exc.InvalidDefinitionException
随机推荐
Towhee 每周模型
线程和进程
Record the star user of handsomeblog
Jmeter接口测试, 快速完成一个单接口请求
Web3.0 world knowledge system sharing - what is Web3.0
The latest multi-threaded & highly concurrent learning materials, interview confidence
中断、信号、系统调用
uni-app 微信小程序搜索关键字标红显示
go语言慢速入门——包
Multipoint bidirectional republication and routing strategy topology experiment
Northeast Securities stock online account, is it safe to open an account on your mobile phone
[Fibonacci sequence and spiral are based on C language]
JMeter interface test, quickly complete a single interface request
JVM interview questions (necessary for interview)
[use SQLite3 library to realize student information management system in Visual Studio 2019]
Hcip OSPF interface network interface type experiment
[enchanting interpretation, 15 minutes let you thoroughly learn how to use the stack!!!]
Okaleido Tiger 7.27日登录Binance NFT,首轮已获不俗成绩
As for the pit saved by serialized variables, the data added with indexer cannot be serialized
砺夏行动|源启数字化:既有模式,还是开源创新?