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

版权声明:吸猫大法、 https://blog.csdn.net/sasuke__/article/details/79069855

首先说一下三次握手过程

一下摘自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了

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

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

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



猜你喜欢

转载自blog.csdn.net/sasuke__/article/details/79069855