状态 | 描述 |
LISTEN | represents waiting for a connection request from any remote TCP and port. |
SYN-SENT | represents waiting for a matching connection request after having sent a connection request. |
SYN-RECEIVED | represents waiting for a confirming connection request acknowledgment after having both received and sent a connection request. |
ESTABLISHED | represents an open connection, data received can be delivered to the user. The normal state for the data transfer phase of the connection. |
FIN-WAIT-1 | represents waiting for a connection termination request from the remote TCP, or an acknowledgment of the connection termination request previously sent. |
FIN-WAIT-2 | represents waiting for a connection termination request from the remote TCP. |
CLOSE-WAIT | represents waiting for a connection termination request from the local user. |
CLOSING | represents waiting for a connection termination request acknowledgment from the remote TCP. |
LAST-ACK | represents waiting for an acknowledgment of the connection termination request previously sent to the remote TCP (which includes an acknowledgment of its connection termination request). |
TIME-WAIT | represents waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request. |
CLOSED | represents no connection state at all. |
重点解读:
1. 数据包类型和作用:
SYN - 同步序列编号,用于发起连接请求
SYN,ACK - 同步序列编号和确认,用于响应连接请求。
ACK - 确认,用于确认接收到的数据或连接请求。
FIN - 终止,用于发起连接关闭请求。
RST - 重置,用于立即终止连接或拒绝连接请求。
FIN,ACK - 终止和确认,用于在关闭连接过程中确认接收到的FIN。
2. 图中实线表示 client端状态转换, 虚线表示server端的状态转换
3.建立连接, TCP三次握手,1、3是client端,2 、4是server端:
3. TCP关闭,4次挥手:
4. Simultaneous Open(同时打开),这种情况不常见。
-
定义:这是指两个TCP端点在几乎同一时间尝试发起连接的过程。
-
过程:
-
同时发送SYN段,进入SYN_SENT状态。
-
双方接收到对方的SYN段,进入SYN_RCVD状态。
-
然后双方都发送SYN-ACK(SYN和ACK的组合),再次进入SYN_SENT状态。
-
最后,双方接收到对方的ACK段,进入ESTABLISHED状态,连接建立。
-
-
场景:这种情况在实际应用中不常见,但可能出现在对等网络(P2P)中,其中两个节点同时尝试建立连接。
5. 理解这张图的难点是:这张图是状态转移图,不是按时间线走的
所以根据不同场景从状态转移图里面标识出时间线,那么就容易理解了。
状态转移举例说明:
比如 SYN_SENT 表示 发送了 SYN 包后的状态,
client端和server端都可以发起连接(tcp Simultaneous ) 。
SYN_SENT 的前一个状态可能是: closed(client) 或者 listen(server),
他的下一个状态:
1正常情况: 接收到自己已发送SYN包的ACK 和对方的SYN请求 ,回复对法SYN(发送ACK), 流转到 established 连接已建立(只是发起方单向连接,接受方还需要收到ACK 后才行)
2只收到了SYN, 自己发送的SYN 对应的 ACK 还没到达,那么状态就转成syn_rcvd ,等待自己SYN 包的ACK
3 超时:自己发送SYN后,达到超时时间后,啥也没收到,超时关闭