One type of network TCP three-way handshake, waving four times Detailed

      Three-way handshake, the fourth wave can be said to be a hot face questions, take a look at what it looks like now!

      We first flow chart Tieshanglai: 

            

         Why so complicated? Because TCP is a reliable transport.

         Confirm the reliable transmission of premise:  TCP connection management mechanism

         TCP header with a field control to manage TCP connections:

         Three-way handshake (a connection):     twice a connection request (SYN) + twice acknowledgment (ACK)

            Process : After entering the LISTEN state server, the client sends to the server SYN connection request, the server receives and sends ACK response SYN connection request, the client receives the response and then sends an ACK to the server, then the connection is established success.

         Four wave (disconnected): Two disconnect request (FIN) + two acknowledgment (ACK)

            Process : active OFF uncertain side, positive off FIN sends a disconnect request, the passive side CLOSE_WAIT state enters replies an ACK response, the passive side closes the connection before sending a disconnection request FIN, positive off party replies an ACK response into the TIME_WAIT state passive square off after receiving the ACK, the active side after 2MSL off, disconnected at this time successful.

          

         Q1: Why is the service end first into the LISTEN state?

         A1: at the application layer is to call the listen function, the socket into a passive state , allowing other clients and servers to establish a connection.

 

         Q2: how to establish a successful connection is disconnected considered successful??

            A2: both ends entering ESTABLISHED state, have entered COLSED state.

 

         Q3: Why should TIME_WAIT state, directly off do not you?

         A3: retransmission control  , in order to ensure that the final ACK lost a retransmission can determine the other party to confirm. The client process has gone, but there are still a TCP connection, if the passive side did not receive ACK, it will timeout retransmission FIN, so

 

         Q4: Why is 2MSL?

         A4: it will take up memory connection exists, it can not always existed, and so 2MSL reasonable.

           1.MSL is a datagram walked from one end of the other end of the maximum time consumed , 2MSL can guarantee segment two transmission was not received or late disappear (or if the server is restarted immediately, will receive on a process The data)

           2. theoretically guarantee last ACK reliable arrival (assuming that lost, TCP connection is still, then the server can timeout retransmission FIN )

 

         Q5: Why is the three-way handshake, four wave?

         A5: three-way handshake is because the service receives SYN, SYN and ACK can be sent directly reply to synchronize .

           When the server receives FIN, core initiative to respond to ACK, the application layer calls the close will be sent FIN . It can also be waved three times with piggybacking.

 

           Q6: how to do if the client fails suddenly appeared?

         A6: TCP handling exceptions provided keepalive timer : If the sender does not receive any data within a predetermined time, to send a heartbeat packet at this time, the hair several times, if not respond to disconnect.

 

         Q7: Why can not connect with twice?

            A7: 1. Three can ensure that both parties know each other ready

           2. Allow the two sides negotiate the initial sequence number , serial number during the handshake is sent and acknowledged .

        

 

Guess you like

Origin www.cnblogs.com/Duikerdd/p/11731602.html