1. TCP application scenarios

TCP provides common reliability scenarios such as HTTP, message queue, storage, and cache.

Two, TCP unpacking and sticky packet

TCP is a transport layer protocol. When TCP sends data, oftenDon’tSend the data all at once, as shown below:

Instead, you take the dataBreak upInto many parts, and then send them one by one. It looks like this:

The packet cannot be too large at the transport layer:

  • The data is split into pieces that do not exceed the size of the buffer
  • Each part has a unique name called TCP Segment.
  • When receiving data, each TCP segment is reassembled into the original data

Unpacking is to split the data into multiple TCP segments for transmission. Sticky packets are sent by combining multiple data into one TCP segment.

Third, the TCP segment

  • Source Port/Destination Port describes the sending Port number and the Destination Port number, representing the application that sends data and the application that receives data. For example, 80 usually represents HTTP service and 22 usually represents SSH service.
  • Sequence Number and Achnowledgment Number are two keys to ensure reliability.
  • Data Offset is an Offset. The reason this quantity exists is that the length of the TCP Header part is variable, so a numeric value is needed to describe which byte the data starts from.
  • Reserved is an area that many protocol designs reserve for later expansion of capabilities.
  • URG/ACK/PSH/RST/SYN/FIN are flag bits that describe the behavior of the TCP segment. What exactly does a TCP packet do?

1) URG means that the data is urgent. For example, when the user presses Ctrl+C to terminate the program during remote operation, the request needs urgent processing.

2) ACK on behalf of the response, we in the “02 | transport layer protocol TCP: why TCP handshake is a wave is 4 times, three times?” As mentioned, all messages must have an ACK, which is part of the TCP protocol to ensure stability.

3) PSH stands for data push, which means data is being transmitted.

4) SYN synchronous request, i.e. Request handshake.

5) The FIN terminates the request, also known as a wave.

The above five flag bits, each occupying a bit, can be mixed. For example, if ACK and SYN are both 1, the synchronous request and response have been merged. That’s one of the reasons why TCP is a three-way handshake.

6) Window is also a tool for TCP to ensure stability and control traffic.

7) The TCP segment Checksum is used to check whether the TCP segment is corrupt.

8) Urgent Pointer points to the Sequence Number of the last Urgent data. It exists because sometimes emergency data is multiple segments in a row, so the receiver needs to be told in advance to prepare.

9) Options stores some optional fields, such as MSS (Maxiumun Segment Size) which we will discuss next. 10) Padding exists because the length of Options is not fixed, which requires Pading to align.

Acknowledgement Number(ACK)

In the design of TCP protocol, the data is divided into many parts, some of which add the protocol header. Combined into a TCP segment for transmission. This process is commonly known as unpacking. These TCP segments go through a complex network structure, with the underlying IP protocol responsible for transport to the destination, and then reassembled.

Stability requires that data be transmitted losslessly, that is, unpacked data needs to be restored to its original form. In a complex network environment, even if all segments are sent sequentially, there is no guarantee that they will arrive sequentially. Therefore, every TCP segment sent requires an order number. This Sequence Number is the Sequence Number (Seq).

Five, the answer

How does TCP restore the order of data? What is the function of TCP unpacking and sticky packet?

TCP packet unpacking is used to split tasks to reduce the error probability of the whole task and reduce the pressure on the underlying network. During the unpacking process, data must be transmitted over the network and restored to the original order. In the middle, mathematics is needed to provide the theoretical basis for guaranteeing the order. TCP uses uniqueness (number of bytes sent, number of bytes received) to determine the sequential relationship between packets. Multiple TCP segments are combined into one packet to prevent a large amount of data from being transmitted.