TCP is used everywhere. Understanding the working principles of TCP helps administrators correctly diagnose network communication faults.
The TCP protocol is complex. But don't worry. We didn't ask you to read RFC 793. This is just an initial lecture. In this lecture, we will only introduce the knowledge required for the next lecture on TCP protocol. After learning this article, you will understand some TCP-related terms and the components of the TCP packet header. Then, we will focus on some common TCP problems in the next article, including TCP Window scalability, blocking, and TCP connection mechanism.
We sometimes hear people mention "TCP/IP protocol stack ". This means they are talking about Layer 1 to Layer 4 and Layer 7 issues, where the TCP protocol is located on Layer 4. It represents the Transmission Control Protocol ). Do you still remember the composition of the protocol header in the IP Protocol article? When a packet is encapsulated, the layer-3 certainly has an IP protocol header followed by the TCP protocol header. The TCP header is the "data" in the IP header ". Just as other protocols have their own terms, TCP also has their own special terms, such as Ethernet frames, IP datagram, and current TCP segments. You can treat them as data packets. However, when communication between them, you must use the correct terminology.
TCP is an end-to-end protocol. Using TCP does not have any broadcast or similar concepts. To use the TCP protocol to communicate with another computer, the two machines must be connected like a phone call, and each end is prepared for the call. Stream delivery is another common term for TCP. The meaning of this phrase is that the TCP protocol is mainly used to process data streams and can correctly process unordered data packets. The TCP protocol even allows the loss or damage of data packets. In the end, it can obtain the data packets again. You may hear a programmer talking about the concept of "stream. It refers to the fact that it is hard to tell when data is sent. You can also send unstructured data in a TCP stream. TCP caches data in its own way. However, the cache process is transparent to programmers and users.
Each packet sent by the TCP protocol receives a confirmation message. This transmission/response mode is the only way to provide reliable protocols: You must let the recipient know whether you have received the data. Of course, this will also cause some performance losses, and people need to improve the system efficiency is not high. Therefore, the "piggybacking ACKs)" method is introduced. The reason why the TCP protocol is full-duplex is that this "accept with validation" message allows both parties to send data simultaneously. This is achieved by carrying the confirmation information of the previously received data in the current data packet. From the perspective of improving network utilization, this is much better than simply sending a packet that notifies the other party that the information has been received. Finally, there is also the concept of batch validation: that is, more than one data packet is confirmed at a time, indicating that "I have received all the data packets including this data packet ".
In the IP protocol, a single packet we process is part of a larger datagram. Remember that a TCP segment is a single TCP packet. TCP is a data stream. Therefore, there is no other concept to worry about except for "connection. The maximum message segment length (MSS) is negotiated during connection, but it is constantly changing. The default maximum packet segment length is 536 bytes, Which is 576 bytes (the minimum packet length guaranteed by the IP protocol) the length after the 20 bytes used for the IP header and the 20 bytes used for the TCP header. The TCP protocol should avoid segment at the IP level. Therefore, TCP always starts from 536 bytes.
The most attractive features of TCP are retained. This is the sliding window protocol. This window is actually the total number of "no receipt confirmation" data that has been sent. This window can be enlarged or reduced as needed. This is interesting. In the next lecture, we will introduce this aspect.
The header of a TCP packet is 20 bytes, just like an IP packet. If some options are used, IP addresses and TCP headers can be enlarged. The TCP Header does not contain an IP address. It only needs to know which port to connect. However, you should not be confused by this. During TCP operations, you must keep track of the end-to-end connections in the status table. This status table contains IP addresses and ports. This means that the TCP Header does not need IP information because it comes from the IP header.
It is easy to imagine a data packet as a data stream of one byte followed by one byte. Many people want a table that displays the TCP header. However, this will often confuse things. The TCP headers start from the first one with the following content:
• Source Port, 16 bits: The local TCP port used for this connection.
• Destination Port, 16 bits: TCP port of the target communication machine.
• Serial number, 32 bits: the number used to track the sequence of data packets.
• Confirmation number, 32 bits: The serial number we have previously received.
• Header length, 4 bits: the number of 32-bit words in the header. If you do not use the option, set this value to 5.
• Reserved, 6 bits: Reserved bytes for future use.
• Mark, with a total of 6 bits: Each mark a byte (ON or OFF)
-URG: Emergency Field pointer.
-ACK: This packet is (or contains) a confirmation message.
-PSH: Push function (not used ).
-RST: reset or interrupt the connection.
-SYN: synchronize data packets, that is, start the connection.
-FIN: The last packet that starts to end the sequence.
• Window size, 16 bits: start with the validation field received by the receiver.
• Checksum, 16 bits: TCP header and data checksum.
• Emergency pointer, 16 bits: The Offset Value pointing to the serial number of the data following the URG data.
• Options: MSS and window ratio. In the next section about TCP, we will focus on this part.
Both ends of the TCP connection use two pairs of IP addresses and ports to identify the connection and send data to the application listening on this port.
First, we will introduce so much content. There is still a lot of content about the TCP protocol.
Summary
TCP is the most common protocol, which is located on the fourth layer in the protocol stack.
TCP provides blocking control, reliability, and data transmission streams.
To improve efficiency, TCP strives to send as much data as possible before being confirmed.
Lecture 8 on basic network knowledge: a preliminary understanding of the IP protocol
Lecture 7: understanding and using ICMP protocol
Lecture 6 on basic network knowledge: Implementing subnets, including IPv6)
Lecture 5: Learning Spanning Tree Protocol
Lecture 4: understanding the data link layer
Network basics Lecture 3: Understanding OSI network layering
Network basics Lecture 2: Understanding subnet and CIDR
One of the basic network knowledge lectures: understanding the meaning of IPv4 addresses