首先说一下三次握手过程
一下摘自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
and acknowledgement number
, which Alice receives.
- Alice replies with an acknowledgment (ACK) message with acknowledgement number
, which Bob receives and to which he doesn't need to reply.
- The first host (Alice) sends the second host (Bob) a "synchronize" (SYN) message with its own sequence number
- 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
, and finally the client responds by sending a segment with 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了
另外附一下标志各自段的意义:传送门
还有各个状态的意义:传送门
顺手附一下知乎上关于为何只有三个包的原因:传送门
TCP三次握手详解
本文详细解析了TCP连接建立过程中的三次握手步骤。包括客户端发送SYN消息、服务器回应SYN-ACK消息及客户端最终确认ACK的过程。解释了同步和服务请求如何通过这些消息实现,以及为何选择特定序列号的重要性。
4742

被折叠的 条评论
为什么被折叠?



