Understanding TCP protocol based on message format

Source: Internet
Author: User

TCP protocol specifies a common method for reliable data stream transmission between different hosts, such as connection establishment and release, message number, confirmation after receiving the datagram, traffic control, and sending timeout. I learned these things by rote, and I forgot it in a few days. I found that learning about this knowledge based on the TCP Message format has a good effect. As shown in the figure below (this figure comes from the Network), we can recall most of the TCP Protocols:

(This figure is from the Network)

Source Port, destination port: source port number, target port number. IP addresses implement point-to-point data communication, while TCP implements end-to-end communication. The communication end is uniquely identified by an IP address and port number. (In fact, the port number is used to identify different processes in the same host .) The IP protocol is used to transmit data to the target host. TCP can send the data to the corresponding program for Processing Based on the port number in the datagram.

Sequence Number: The sending serial number. IP addresses implement point-to-point communication, which is unreliable. IP datagram may be lost or arrive at the target host in disorder, while TCP provides a reliable communication method. It can implement reliable communication by numbering the sent data packets (specifically, numbering the data streams. For example, when an application sends 2048 bytes of data to the target host, the TCP protocol first packs the data into one datagram and then numbers it. Assume that the length of the data carried by each datagram is 100 bytes, and the number of the first datagram is 1, the number of the second datagram is 101, the number of the third datagram is 201, and so on.

Acknowledgment number: Check the serial number. For the sender, this sequence number indicates the Starting sequence number of the next TCP packet, and for the receiver, it indicates the sequence number of the next packet to be received.

Data offset: this field occupies 4 bytes to indicate the length of the packet header. The unit is 4 bytes. For example, 0x05 indicates that the header length of a message is 5*4 = 20 bytes.

Reserved: this field occupies 6 bytes and is reserved for the moment.

There are six Identifiers (uaprsf, remember the first letter of each word ):

  1. URG (ENT): If the location is 1, the message is urgent and must be transmitted quickly.
  2. Ack: confirm the serial number. It has something to do with the preceding acknowledgment number. Acknowledgment number is valid only when this position is 1.
  3. Psh: Push. It indicates that after receiving a message, it must be quickly transmitted to the application layer.
  4. RST: reset. Reset the connection.
  5. SYN: synchronous. This identifier is used when a connection is created.
  6. Fin: termination. This identifier is used when the connection is released.

Window: the size of the sliding window. It is used for traffic control between communication parties. To ensure the reliability of communication, TCP serial numbers are sent. After receiving a message, confirm it with the sender. Generally, the sender does not send a message after receiving the confirmation message. The utilization of these networks is too low, but the maximum data size that can be sent when the confirmation message is not received.

Checksum: Checks packets. If the verification fails, the message is discarded.

Urgent Pointer: Smart needle. I still don't know about the details. Some materials on the Internet are explained as follows: pointing to the next byte of the priority data.

Options: Optional. Currently, TCP only defines one option: the maximum length of packets. It is used to tell the other party of the communication about the maximum length of the packet segment that can be received by the protocol frame buffer.

Padding: Fill segment. Ensure that the length of the packet header can be 32.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.