TCP三次握手和四次挥手为何只发送三个包?

本文详细解析了TCP连接建立过程中的三次握手步骤。包括客户端发送SYN消息、服务器回应SYN-ACK消息及客户端最终确认ACK的过程。解释了同步和服务请求如何通过这些消息实现,以及为何选择特定序列号的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先说一下三次握手过程

一下摘自wiki handshake

Establishing a normal TCP connection requires three separate steps:

  1. The first host (Alice) sends the second host (Bob) a "synchronize" (SYN) message with its own sequence number xx, which Bob receives.
  2. Bob replies with a synchronize-acknowledgment (SYN-ACK) message with its own sequence number yy and acknowledgement number x+1x+1, which Alice receives.
  3. Alice replies with an acknowledgment (ACK) message with acknowledgement number y+1y+1, which Bob receives and to which he doesn't need to reply.
In this setup, the synchronize messages act as service requests from one server to the other, while the acknowledgement messages return to the requesting server to let it know the message was received.

One of the most important factors of three-way handshake is that, in order to exchange the starting sequence number the two sides plan to use, the client first sends a segment with its own initial sequence number xx, then the server responds by sending a segment with its own sequence number yy and the acknowledgement number x+1x+1, and finally the client responds by sending a segment with acknowledgement number y+1y+1.

The reason for the client and server not using the default sequence number such as 0 for establishing connection is to protect against two incarnations of the same connection reusing the same sequence number too soon, which means a segment from an earlier incarnation of a connection might interfere with a later incarnation of the connection.

之前一直被直观误导,以为第二次握手过程会发送一个syn包和和一个ack包,才发现syn和ack仅仅只是tcp包中的标志段(。。。)

以下是tcp数据包的格式

理论联系实际:Wireshark抓包分析TCP 3次握手、4次挥手过程_13.jpg

所以WIKI中的解释的(SYN-ACK) message实际是在一个tcp包中将ACK字段和SYN字段都置1了

另外附一下标志各自段的意义:传送门

还有各个状态的意义:传送门

顺手附一下知乎上关于为何只有三个包的原因:传送门



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值