One, connect-and three-time handshake
(1) First handshake : When a connection is established, client A sends a SYN (SYN=J) packet to Server B and enters the syn_send state, waiting for the server to confirm.
(2) Second handshake : Server B receives the SYN packet, must confirm the SYN (ACK=J+1) of customer A, and also sends a SYN packet (syn=k), that is, the Syn+ack package, at which point Server B enters the SYN_RECV state.
(3) The third handshake : Client A receives the server's Syn+ack packet, sends the acknowledgment packet ACK (ack=k+1) to Server B, and the packet is sent, client A and Server B enter the established state and complete three handshake.
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s5.51cto.com/wyfs02/m01/80/68/wkiom1dakz_we_p_aab_y2atk8g890.png "title="]l} $M 2d[' 6]OL9CVS6DHDBK.png "alt=" Wkiom1dakz_we_p_aab_y2atk8g890.png "/>
The meaning of each state:
Syn_send: Wait for a matching connection request after sending a connection request
SYN_RECV: Waits for confirmation of a connection request after receiving and sending a connection request
Established: Represents an open connection to which data can be transmitted to the user
Two, close the connection-four times wave
(1) First wave: client A sends a FIN (FIN=M) to turn off the data transfer from client A to Server B and into the fin_wait_1 state.
(2) Second wave: Server B receives this fin, it sends back an ACK (ack=m+1), the server enters the close_wait state.
"After the server receives the FIN, it returns an ACK and shuts down the server read channel"
"When the client receives an ACK, shut down the client write channel"
(3) Third wave: Server B Closes the connection to client A, sends a FIN (fin=n) packet to client A, and enters the Last_ack state.
(4) Fourth wave: the client receives this fin, it sends back ACK (ACK=N+1) message confirmation, and Server B enters closed state.
"After the client receives FIN, it returns the acknowledgement segment ACK and closes the client read channel"
"Server received ACK, shutdown server write channel"
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s5.51cto.com/wyfs02/m02/80/68/wkiom1daketwkiy1aacgm9tjxjc974.png "title=" Image.png "alt=" Wkiom1daketwkiy1aacgm9tjxjc974.png "/>
The meaning of each state:
Fin-wait_1: Waiting for a connection interrupt request from a remote TCP, or confirmation of a previous connection interrupt request
Close_wait: Waiting for a connection interrupt request from a local user
Fin_wait2: Waiting for connection interrupt request from remote TCP
Last_ack: Waiting for confirmation of a connection interrupt request that was originally sent to remote TCP
Time_wait: Wait enough time to ensure that the remote TCP receives a connection interrupt request acknowledgement
CLOSED: No connection status
Third, why the initiative to initiate the closure of the party will reach the TIME_WAIT state, and this state to maintain 2MSL of time, rather than directly into the closed state? (client active shutdown, Windows default 2msl=240s)
(1) Ensure the TCP protocol full-duplex connection can be reliably shut down
If the client is directly closed, if the server does not receive an ACK from the client's last reply due to an IP protocol unreliability or other network reason, then the server will continue to send fin after the timeout, because the client has closed , the connection to the re-issued fin is not found, and finally the server receives the RST instead of the ack,server and then reports the problem to the upper level as a connection error. Such a situation does not result in data loss, but it causes the TCP protocol to not meet the requirements of a reliable connection. Therefore, the client is not directly into the closed, but to maintain the time_wait, when again received fin, can ensure that the other side received an ACK, and finally close the connection correctly.
(2) To ensure that the duplicate data segment of this connection disappears from the network
If the client closed directly and then initiates a new connection to the server, if the port number for the new connection and the old connection is the same, some data for the previous connection is still stuck in the network, and the deferred data arrives at the server after the new connection is established. Because the new connection is the same as the port number of the old connection, and because the TCP protocol determines that the different connections are based on the socket pair, the TCP protocol considers the delay data to be new, which leads to confusion with the packets that are really new to the connection. So the TCP connection also waits for 2MSL time in the time_wait state, so that all the connected data will disappear from the network at this time.
Four, window
When a connection is established, each side allocates a buffer to store the received data and sends the buffer's dimensions to the other end, and the acknowledgment sent by the receiver contains its remaining buffer size, and the amount of remaining buffer space is called the window.
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s5.51cto.com/wyfs02/m00/80/66/wkiol1dakwuqir3daaflylir5ig644.png "title=" Image.png "alt=" Wkiol1dakwuqir3daaflylir5ig644.png "/>
TCP three-time handshake and four waves