TCP小笔记
握手
TCP连接状态
三次握手
下面是状态的解释:
State | Description |
---|---|
LISTEN | The socket is listening for incoming connections. Such sockets are not included in the output unless you specify the --listening (-l) or --all (-a) option. |
SYN_SENT | The socket is actively attempting to establish a connection. |
SYN_RECV | A connection request has been received from the network. |
ESTABLISHED | The socket has an established connection. |
四次释放
上面的网图看着还是挺清晰的,但是有个小瑕疵,就是不应该是客户端对服务端,而是主动关闭端对应被动关闭端。主动关闭端要求进入TIME_WAIT
状态。
下面是各种状态的解释:
State | Description |
---|---|
ESTABLISHED | The socket has an established connection. |
FIN_WAIT1 | The socket is closed, and the connection is shutting down. |
FIN_WAIT2 | Connection is closed, and the socket is waiting for a shutdown from the remote end. |
TIME_WAIT | The socket is waiting after close to handle packets still in the network. |
CLOSE | The socket is not being used. |
CLOSE_WAIT | The remote end has shut down, waiting for the socket to close. |
LAST_ACK | The remote end has shut down, and the socket is closed. Waiting for acknowledgement. |
CLOSING | Both sockets are shut down but we still don’t have all our data sent. |
TIME_WAIT重置场景
主动端关闭连接之后,被动端发送了FIN报文代表被动端也想要关闭连接。此时,主动端发送的确认报文失效。
被动端没有收到FIN的确认报文,因此重发FIN报文,主动端收到会重置时钟,发送ACK确认报文。