TCP/IP transport protocol, namely transmission control/network protocol, also known as network communication protocol. It is the most basic communication protocol in the use of network. TCP/IP protocol specifies the standards and methods for communication between different parts of the Internet. And, TCP/IP transmission protocol is to ensure the network data information timely and complete transmission of two important protocols. TCP/IP transport protocol is strictly a four-tier architecture, including the application layer, transport layer, network layer and data link layer.

Notes Xmind

Three-way handshake & Disconnection of data capture

Three-way handshake

  1. First handshake: The client sets the SYN flag bit to 1, randomly generates a value seq=J, and sends the packet to the server. The client enters the SYN_SENT state and waits for the confirmation from the server.
  2. Second handshake: When the server receives the packet, the flag bit SYN=1 knows that the client requests to establish a connection. The server sets the flag bit SYN and ACK to 1, ACK =J+1, randomly generates a value seq=K, and sends the packet to the client to confirm the connection request. The server enters the SYN_RCVD state.
  3. Third handshake: After receiving the confirmation, the client checks whether the ACK is J+1 and ACK is 1. If yes, the client sets the flag ACK bit to 1, ACK =K+1, and sends the packet to the server. The server checks whether the ACK is K+1 and ACK is 1. The client and server enter the ESTABLISHED state and complete the three-way handshake. Data can then be transferred between the client and server.

Four times to wave

  1. First wave: The client sends a FIN=M to close the data transfer from the client to the server and the client enters the FIN_WAIT_1 state. This means “I have no more data to send to you from the client”, but if you have data to send from the server, there is no need to close the connection and continue to send data.
  2. Second wave: After receiving the FIN, the server sends ack=M+1 to tell the client that I have received your request, but I am not ready yet. Please continue to wait for my message. In this case, the client enters the FIN_WAIT_2 state and waits for the FIN packet from the server.
  3. Third wave: When the server confirms that data has been sent, it sends a FIN=N packet to the client to tell the client that all data has been sent and that it is ready to close the connection. The server enters the LAST_ACK state.
  4. Fourth wave: After receiving the FIN=N packet, the client knows that the connection can be closed. However, the client still does not trust the network, fearing that the Server does not know to close the network. Therefore, the client sends ack=N+1 and enters the TIME_WAIT state. When the server receives an ACK, it knows it is ready to disconnect. If the client waits for 2MSL and still does not receive a reply, then the server is shut down normally, then the client can also close the connection. Four handshakes were completed

The whole process

First, let’s sort out the responsibilities of each layer of model:

  • Link layer: groups 0 and 1, defines data frames, confirms the physical address of the host, and transmits data.
  • Network layer: Defines THE IP address, identifies the network location of the host, addresses the MAC address through THE IP address, and forwards packets on the external network.
  • Transport layer: define the port, confirm the identity of the application on the host, and deliver the packet to the corresponding application;
  • Application layer: Defines the data format and interprets the data according to the corresponding format.

Then the responsibilities of each layer of the model are linked together in a simple and understandable way:

When you enter a url and press Enter, the application layer protocol formats the request packet. Then the transport layer protocol adds the port number of both sides, confirming the application of communication between the two sides; The network protocol then adds the IP addresses of both parties to confirm the network location of both parties. Finally, the link layer protocol adds the MAC addresses of the two parties to confirm their physical locations. At the same time, data is grouped to form data frames, which are broadcast and sent to the host of the other party through the transmission medium. For different network segments, the packet is first forwarded to the gateway router and finally sent to the target host after multiple forwarding. After receiving the packet, the target machine uses the corresponding protocol to assemble the frame data, and then parses the frame data through layer by layer protocol. Finally, the frame data is parsed by the protocol of application layer and handed to the server for processing.

reference

Finally someone who can spell out TCP/IP! www.cnblogs.com/onepixel/p/…