TCP三次握手和四次揮手為何只傳送三個包?
首先說一下三次握手過程
一下摘自wiki handshake
Establishing a normal TCP connection requires three separate steps:
-
- The first host (Alice) sends the second host (Bob) a "synchronize" (SYN) message with its own sequence number , which Bob receives.
- Bob replies with a synchronize-acknowledgment (SYN-ACK) message with its
own sequence number
- Alice replies with an acknowledgment (ACK) message with acknowledgement number , 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 ,
then the server responds by sending a segment with its own sequence number and
the acknowledgement number
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資料包的格式
所以WIKI中的解釋的(SYN-ACK) message實際是在一個tcp包中將ACK欄位和SYN欄位都置1了
另外附一下標誌各自段的意義:傳送門
還有各個狀態的意義:傳送門
順手附一下知乎上關於為何只有三個包的原因:傳送門