Graphic TCP-IP protocols (1)
In this paper, two diagrams are used to sort out the knowledge of TCP-IP protocol. The TCP communication process consists of three steps: establishing a TCP connection channel, transmitting data, and disconnecting a TCP connection channel. 1 shows the TCP communication process.
Figure 1 TCP three-way handshake
Figure 1 consists of three parts: establishing a connection, transmitting data, and disconnecting.
1) it is easy to establish a TCP connection. You can establish a connection through three handshakes.
2) After the connection is established, data transmission starts. TCP data transmission involves many concepts: timeout retransmission, fast retransmission, traffic control, and congestion control.
3) The process of disconnecting is also very simple. The process of disconnecting is completed through four handshakes.
Three-way handshake to establish a connection:
The first handshake: the client sends the syn Packet (seq = x) to the server and enters the SYN_SEND status, waiting for confirmation from the server;
The second handshake: when the server receives the syn packet, it must confirm the customer's SYN (ack = x + 1) and send a SYN Packet (seq = y), that is, SYN + ACK packet, the server enters the SYN_RECV status;
The third handshake: the client receives the server's SYN + ACK package and sends the ACK (ack = y + 1) Confirmation package to the server. After the package is sent, the client and server enter the ESTABLISHED status, complete three handshakes.
The package transmitted during the handshake does not contain data. After the three-way handshake is completed, the client and the server formally start to transmit data. Ideally, once a TCP connection is established, the TCP connection will remain until either of the two parties closes the connection.
Data transmission process:
A. Timeout retransmission
The timeout retransmission mechanism is used to ensure the reliability of TCP transmission. Each time a data packet is sent, the sent data packet has a seq number. After receiving the data, the receiving end replies to ack for confirmation, indicating that the data of a certain seq number has been received. After sending a seq packet, the sender waits for a period of time. If the corresponding ack reply is not received, the sender considers the packet to be lost and retransmits the packet.
B. Fast retransmission
The recipient finds that some data packets are lost. An ack packet is sent to the sender to send the lost packet. If the sender continuously receives an ack packet with the same label, the fast retransmission of the client is triggered. Compared with timeout retransmission and fast retransmission, it can be found that the sender times out while the sender triggers retransmission. The fast retransmission means that the receiver actively tells the sender that the data has not been received, then trigger the sender retransmission.
C. Traffic Control
TCP Sliding Window traffic control. There is a field in the TCP Header called Window, also called Advertised-Window. This field is used by the receiving end to tell the sending end how many buffers can receive data. Therefore, the sender can send data based on the processing capability of the receiver, without causing the receiver to be unable to process the data. Sliding windows can be a mechanism to improve TCP transmission efficiency.
D. Congestion Control
The sliding window is used for traffic control. Traffic control only focuses on the status of the sender and receiver, rather than the communication of the entire network. Congestion Control is based on the entire network. Consider this scenario: when the network latency increases suddenly at a certain time point, TCP will only respond to this issue by re-transmitting data. However, re-transmission will cause a heavier network burden, as a result, it will lead to a greater delay and more packet loss. Therefore, this situation will go into a vicious circle and be magnified. Imagine if tens of thousands of TCP connections in a network do this, a "network storm" will be formed immediately, and the TCP protocol will drag the entire network. Therefore, TCP introduces a congestion control policy. Congestion policy algorithms include slow start, congestion avoidance, congestion occurrence, and rapid recovery.
Disconnect after four handshakes:
The first wave: Send a FIN to the active side to the passive side to close the data transmission from the active side to the passive side, that is, the active side tells the passive side: I will not send you any more data (of course, the data sent out before the fin package will still be resold if the corresponding ack confirmation message is not received ), however, the disabled party can accept the data.
Second wave: After the passive close party receives the FIN packet, it sends an ACK to the other party and confirms that the serial number is the received serial number + 1 (same as SYN, one FIN occupies one serial number ).
The third wave: Send a FIN from the passive closing party to the data transmission from the passive closing party to the active closing party, that is, tell the active closing party that my data has been sent, no more data will be sent to you.
The fourth wave: After the active closing party receives the FIN, it sends an ACK to the passive closing party and confirms that the serial number is the received serial number + 1. At this point, the four waves are completed.