1、客户端连接服务器时:
可以看到:
(1)客户端发送SYN,然后服务器回复SYN+ACK,然后,客户端在回复ACK。
2、TCP断开时,分为2种情况,(1):客户端先断开,(2)服务器先断开。注意:说先断开,谁先发送FIN包
(1)客户端先断开:
可以看到:
客户端先发送了FIN+ACK,然后服务器回复ACK包。
(2)服务器先断开:
可以看到:
服务器先发送FIN+ACK,然后客户端发送ACK,然后客户端再回复FIN+ACK,然后服务器回复ACK。
注意:(1)服务器断开是4次挥手,客户端断开是2次挥手。
(2)当客户端和服务器长期空闲状态时,客户端会发强制断开的数据包RST+ACK,如下: