Current location - Quotes Website - Team slogan - What is the format of TCP message and the working principle of TCP protocol?
What is the format of TCP message and the working principle of TCP protocol?
TCP message format

Source port and destination port: 16 bits, indicating the port numbers of the sender and receiver respectively. Port number and IP address constitute the main content of socket address. Sockets at the source and destination together uniquely represent a connection. Network applications send and receive data directly to sockets during communication.

Serial number and confirmation number: both are 32-bit unsigned integers, which can represent the range of 0-4G(232) bytes. Among them, the sequence number indicates the sequence number of the first byte of the data part, and the acknowledgement number indicates the sequence number of the next byte that the receiver of the datagram wants the other party to send (that is, the data with the sequence number less than the acknowledgement number has been correctly received).

Header length (HLEN): indicates the length of the TCP header. The length is calculated in units of 32 bits. So if the length of the option part is not an integer multiple of 4 bytes, it should be padded.

Reserved field: The header length field is followed by 6 bits, which should be set to 0.

Then there are six flags. The specific meaning of the flag bit:

URG is an emergency data flag. If it is 1, this datagram contains urgent data. At this time, emergency data refers to

The value indicated by pin is valid. It represents the offset value of the first byte after the emergency data (that is, the total length of the emergency data).

ACK is a confirmation flag bit. If the ACK is 1, it means that the confirmation number in the message is valid. Otherwise, the message

The confirmation number in is invalid, and the receiver can ignore it.

PSH (push) flag bit. After the setting is completed, the TCP protocol software of the sender is required to send the datagram immediately, and the receiver should submit the data to the application immediately after receiving the data, even if its receiving buffer is not full.

RST (reset) flag bit. Used to reset the connection. Messages with the RST flag set are called reset messages. Generally speaking, if the message received by TCP obviously does not belong to any connection on the host, it will send a reset message to the far end.

Synchronization flag. Used to establish a connection so that both parties can synchronize the serial number. If SYN= 1 and ACK=0, the datagram is a connection request; If SYN= 1 and ACK= 1, the connection is accepted.

The FIN flag bit. Indicates that the sender has no data to transmit and wants to release the connection.

A window field. This window indicates the maximum number of bytes that the sender can send continuously from the acknowledged bytes. By setting the value of this window, the receiver can adjust the speed at which the source sends data, thus realizing flow control.

Checksum field. Is an error detection mechanism provided by TCP protocol. Similar to the UDP protocol we learned in the last chapter, when calculating the checksum, we should not only calculate the TCP message itself (header and data), but also add some extra information content-12 byte "pseudo header".

TCP/IP (short for Transmission Control Protocol/Internet Protocol, translated from Chinese into Transmission Control Protocol/Internet Protocol) is the most basic protocol of the Internet. Simply put, it is composed of the underlying IP protocol and TCP protocol.

Before the internet appeared, many small networks called local area networks were established in various places. Internet, which means "Internet" in Chinese, is actually a "network between networks" formed by connecting local areas around the world. However, before the connection, the network structure and data transmission rules of various LANs are different. What rules should be adopted to transmit data after these small networks are connected? It's like there are many countries in the world, and people in each country speak their own language. How can any two people in the world communicate? If people all over the world can speak the same language (Esperanto), wouldn't this problem be solved? TCP/IP protocol is the "Esperanto" on the Internet.

The development of TCP/IP protocol began in 1970s, and it is the first set of protocols used on the Internet.