Computer Network Basics (15)-Transport Layer-Detailed Explanation of TCP Protocol

Article content overview

Introduction to TCP protocol

  • TCP (Transmission Control Protocol: Transmission Control Protocol)
  • TCP protocol is a very complicated protocol in computer network

The location of the TCP datagram

Features of TCP protocol

TCP is a connection-oriented protocol

In the last UDP protocol detailed explanation , connection-oriented was introduced, that is, the connection will be established before communication

A TCP connection has two ends (point-to-point communication)

A and B want to communicate by phone, then A and B are two endpoints

TCP provides reliable transmission services

A detailed introduction to TCP's implementation of reliable transmission will be given later.

TCP protocol provides full-duplex communication

Full duplex is mentioned in the network overview, which refers to a communication line in which both parties can send and receive messages at the same time . In other words, if two computers establish a TCP connection, then both computers can send data to or receive data to the connection at the same time

TCP is a surface of the byte stream protocol

When I introduced UDP in the last article , I knew that UDP is a protocol for user datagrams. So what is the difference between datagram and byte stream?

Stream refers to the sequence of bytes flowing into or out of the process. The data of the transport layer is transmitted by the application layer, which is a complete piece of data. But in TCP, it does not regard the data transmitted by the application layer as a complete piece of data, but as a whole byte stream. TCP does not deal with a whole block of data, but deals with one byte by one. Therefore, TCP may take out a certain segment of a piece of data for transmission, and then put the remaining data in the second TCP packet for transmission. Therefore, when using TCP protocol for data transmission, the data may be combined or split to achieve better transmission.

TCP protocol header

The source port and destination port of 16 are the same as those in UDP

Serial number : The serial number occupies a total of 32 bits, so the range it can represent is 0~2^32. Because the TCP protocol is byte-oriented, each byte has a unique serial number, which is used to mark each byte transmitted (one serial number per byte). The serial number here represents what is the serial number of the first byte of the data transmitted by this TCP packet

Confirmation number : The range of confirmation number is also 0~2^32, which is also a confirmation number per byte. The confirmation number indicates what the sequence number of the first byte of the expected data is

Suppose there is a TCP datagram, its sequence number is 501, and the data length is 100 bytes. When a computer receives this data, the confirmation number will say that I have already received the data in the range of 501 to 600, and I expect the next confirmation number to be passed to me is 601. So the acknowledgment number means that I expect the sequence number of the first byte of the data in the next datagram . The confirmation number is used together with the serial number.

If the data acknowledgment number of a TCP datagram is N, it means that the data of the N-1 sequence number has been received

Data offset :

  • Occupies 4 bits (0~15), the unit is a 32-bit word, that is to say, each offset can represent an offset of 4 bytes
  • It represents the real TCP data, the distance it deviates from the header (this is mainly caused by the content of the TCP option block, because we don't know how much the content of this option is, so we need to store the data offset)
  • The TCP header has a fixed length of 20 bytes (at least), how many bytes is the longest in the TCP header? At this point, you can perform a simple calculation on the data offset to get the longest TCP header

Because the maximum data offset is 15, each offset can represent 4 bytes. So the maximum offset is 15 times 4 equal to 60 bytes, so the length range of the TCP header is 20~60 bytes

Reserved fields : reserved, unused

TCP flag : occupies 6 bits, each has a different meaning, they are:

in the back to understand the TCP three-way handshake and four waves, will use the flag here

Window : occupies 16 bits, 0~2^16-1. The meaning of the window is to indicate the amount of data allowed to be sent by the other party. If the window size is 1000, it means that the other party can send 1000 bytes

You can also combine the window and the confirmation number to perform an operation. Assume that the confirmation number is 501 and the value of the window is 1000, which means that data between 501 and 1500 bytes can be received

Checksum : inside and UDP checksum and mean the same thing, I can look at the article on UDP articles

Urgent pointer : This is only enabled when the URG=1 of the current TCP flag bit. It indicates that the urgent data is located in the message position. For TCP messages, some urgent data can be stored in the datagram. When the other party receives it, the emergency pointer can be used to find the location of the urgent data in the datagram.

TCP option : It is optional. It can be known from the previous calculation of the data offset that the TCP option has a maximum of 40 bytes. This option is mainly used to support the future development of the protocol (support future expansion)

Insert picture description here

Guess you like

Origin blog.csdn.net/self_realian/article/details/107857901