Data transmission must comply with transmission control Protocol (TCP). TCP supports data transmission in full-duplex mode, which means data can be transmitted in both directions at the same time. Before transmitting data, TCP is established through a three-way handshake, so after the transmission, the connection must be closed in both directions and waved four times.

Transmission Control Protocol (TCP) is a connection-oriented, reliable, byte stream based transport-layer communication Protocol defined by RFC 793 of the IETF.

TCP setup – Three-way handshake (before sending data)

The detailed process is as follows:

The initiator (PC1 in the figure) sends a TCP packet with the first SYN at position 1. The initial serial number A is a randomly generated number. Since no packet has been received from PC2, the serial number is confirmed to be 0.

After receiving a valid SYN packet, the recipient (PC2 in the figure) replies a TCP packet with the SYN and ACK set to 1. The initial sequence number B is a randomly generated number. Since the packet is a reply packet to PC1, the sequence number is a+1. After receiving the SYN and ACK packets sent by PC2, PC1 replies with an ACK packet with the sequence number a+1 and confirms that the sequence number is B +1. After PC2 receives the packet, the TCP bidirectional connection is established.

TCP shutdown – Four waves (after data is done)

When data transfer is complete, TCP disconnects the TCP connection through the four-wave mechanism to release system resources. As shown in the figure:

  1. PC1 sends a TCP segment with the FIN field set to 1 without data.
  2. After receiving the TCP packet with the FIN bit set from PC1, PC2 replies a TCP packet with the ACK bit set.
  3. If PC2 has no data to send, it directly sends TCP packets with FIN bit. Assuming that PC2 still has data to send, PC2 sends a TCP packet with FIN position to close the connection after sending the data.
  4. PC1 replies with an ACK packet after receiving a FIN TCP packet, and the TCP bidirectional connection is disconnected.

The whole process can be simply understood as:

Three-way handshake: PC1 says to PC2, I want to talk to you, PC2 says, copy, and then asks PC1, can you hear me? If PC1 hears it, it can communicate normally.

Four times wave: the call ends, PC1 says to PC2, I don’t want to talk, PC2 replies, and says to PC1, I don’t want to talk either, and THEN PC1 replies, bye, and the whole call ends.