TCP establishes connection

write in front

A study of the "connection-oriented" properties of TCP. What is connection orientation? Why does TCP use connection-oriented communication? What is the process of establishing a TCP connection?

 

connection-oriented communication

The communication process of establishing a connection: A phone call is a connection-oriented communication, A calls B, B accepts and A has not hung up at this time, the connection is established successfully, and both A and B communicate normally. If B does not accept the call, the connection cannot be established, and the entire communication process cannot be established.

Connectionless communication: Sending a text message is a connectionless communication. A sends a text message to B, and A does not know whether the communication status of B is normal (for example, the mobile phone has power, has a signal, and the mobile phone is not lost). At this time, A can not Restricted by B's communication status, send text messages to B freely. The entire communication process can be achieved without establishing a connection.

 

Advantages and disadvantages of connection-oriented communication

Advantages: high reliability

Disadvantages: In order to guarantee reliability, the whole process is very complicated (you can't have both, the most important thing is to find a balance)

 

TCP status codes

S refers to the server, C refers to the client, S&C refers to both, and S/C refers to either.

LISTEN - S : The server waits for a connection request from any remote TCP port. listening state.

SYN-SENT - C : The client waits for a matching connect request after sending a connect request. The client enters this state after sending a SYNC signal to the server.

SYN-RECEIVED - S : The server has received the client's synchronization (SYNC) signal, and waits for the client's acknowledgment (ACK) request after sending the synchronization (SYNC) signal.

ESTABLISHED - S&C : The connection between the server and the client has been opened, and the data received by the server can be sent to the application layer. Normal case for data transfer steps. At this point the two ends of the connection are equal. This is called a full connection.

FIN-WAIT-1 - S&C : (server or client) actively closes the sending of the FIN request packet, indicating that the data transmission of the party is all over, and waits for the ACK confirmation packet or FIN&ACK request packet from the other end of the TCP connection.

FIN-WAIT-2 - S&C : The active closing end receives the ACK confirmation packet in the FIN-WAIT-1 state, and enters the semi-closed state waiting for the connection termination request of the remote TCP. At this point, data can be received, but no more data will be sent.

CLOSE-WAIT - S&C   : After passively closing the termination to FIN, it sends an ACK in response to the FIN request, and enters a half-closed state waiting for the local user's connection termination request. At this point, data can be sent, but no more data will be received.

CLOSING - S&C : After sending FIN, after receiving the FIN sent by the other party, it enters the state of waiting for the confirmation (ACK) of the other party's connection termination (FIN). rare.

LAST-ACK - S&C : After the passive closing end sends all the data, it sends FIN to the active closing end, and enters the state of waiting for the confirmation packet.

TIME-WAIT - S/C : After the active shutdown end receives the FIN, it sends an ACK packet and waits enough time to ensure that the passive shutdown end receives the acknowledgment packet for the termination request.

CLOSED - S&C : No connection at all.

 

TCP three-way handshake to establish connection

                     

The process of connection establishment requires a total of three communications, and the connection is successfully established after the three communications are successful. The third communication is to confirm that the state of both parties is normal before establishing the connection. It's like making a phone call.

Packet capture analysis during connection establishment:

              

 

Client initiates connection, SYN = 1 

           

 

The server receives the connection request and sends a response packet, SYN = 1, ACK = 1 

         

 

The client sends the response packet after receiving the server's response packet, ACK = 1

          

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325219655&siteId=291194637