First, understand TCP segments
SEQ : SEQ ID NO accounting 32, used to identify the byte stream from the TCP transmission source to the destination, the initiator sends data of this labeling.
The ACK (Acknowledgment): the acknowledgment sequence number bit is 1 if the, data for confirming the sender
Window size: for explaining the number of local data segments may be received, the window size is variable
SYN: synchronization sequence number, the TCP connection is required when the value is set to 1
FIN: When a TCP connection is disconnected is the position 1
ACK (Acknowledgement Number): the acknowledgment sequence number, representing 32, when only the ACK flag bit is 1, the acknowledgment number field is valid, Ack = Seq + 1
Others can refer to: https://blog.csdn.net/mary19920410/article/details/58030147
Two, TCP / IP three-way handshake
Picture in terms of explanation:
CLOSED original (non-connected) state.
LISTEN listening state, waiting for the connection request to the remote machine.
After SYN_SEND the TCP three-way handshake, the active connection sends a SYN packet into SYN_SEND state and wait for an ACK packet.
SYN_RECV the TCP three-way handshake, the active end of the connector receives the ACK packet enters SYN_RECV state.
After ESTABLISHED complete the TCP three-way handshake, end active connections entering ESTABLISHED state. In this case, TCP connection has been established, you can communicate.
TCP three-way handshake is as follows:
1. The client 1 (active connection) sends a SYN packet to the server 2 (passive connection);
Packet to the server 2. Client 2 (passive connection terminal) receives the SYN packet, and sends an ACK with a SYN flag (active connection);
3. Client 1 (active connection) sends a packet with the ACK flag server 2 (passive connection terminal), the handshake operation is completed.
Three, TCP / IP four wave
Picture in terms of explanation:
When TCP four FIN_WAIT_1 disconnected after the active closing FIN packets it sends into FIN_WAIT_1 state.
When four FIN_WAIT_2 TCP disconnect active close the rear end of the ACK packet is received, it enters FIN_WAIT_2 state.
After four TCP TIME_WAIT When disconnected, the closed end of the active ACK packet transmitted into the TIME_WAIT state.
When TCP CLOSE_WAIT four off the closed end of the passive FIN packet is received into CLOSE_WAIT state.
When TCP LAST_ACK four off the rear end of the passive closing FIN packet sent into LAST_ACK state and wait for an ACK packet.
TCP four broken as follows:
1. The client 1 (active connection) sends a FIN packet to the server 2 (passive connection terminal) to disconnect request;
2. Server 2 (passive connection) after receiving the FIN packet, sends an ACK packet to the client 1 (active connection);
3. Server 2 (passive connection terminal) transmits the ACK packet, then the client sends a FIN packet to 1 (active connection) confirmation disconnected;
4. The client 1 (active connection) after receiving the FIN packet, sends an ACK packet, when the server 2 (passive connection terminal) receives the ACK packet, four off operation is completed, the connection is disconnected.