TCP learning of Transmission Control Protocol (1)

Source: Internet
Author: User

Time: 2014.06.25

Location: Base

---------------------------------------------------------------------------------

I. TCP Service

TCP is located between the application layer and the network layer and provides services between applications and network functions. It mainly includes the following services:

1.1 process-to-process communication

Like UDP, TCP also uses port numbers to provide process-to-process communication.

1.2 stream delivery service

Unlike UDP, TCP is a stream-oriented protocol.

In UDP, the process sends the packets with the defined boundary to UDP for delivery. UDP adds its own 8 byte header to each packet and then transmits them to the IP address for transmission. A packet sent from a process is called a User Datagram, which forms an IP datagram. No relationship exists between the datagram, whether UDP or IP.

In TCP, the sending process is allowed to transmit data in the form of a byte stream, and the receiving process is allowed to receive data as a byte stream. It is like two processes are connected with an imaginary pipe. The data between the two processes is transmitted over the Internet.

1.2.1 sending cache and receiving Cache

Because the sending and receiving processes may write data to and read data from the pipeline at different speeds, TCP needs to use cache to store data. Two caches are required: The sending cache and the receiving cache. The cache will also be used by TCP for traffic control and Error Control. The cache implementation is a ring array consisting of 1 byte segments.

In the sender, the sending cache ring array is divided into three areas:

A. empty slot: Allow sending process (producer) to fill in data in the empty slot

B. sent slot: the data has been sent, but no confirmation has been received, so the data is retained in the cache, and the corresponding confirmation is received directly. Once confirmed, the sent slot will be recycled into an empty slot and sent again for use.

C. unsent slot: the data has been filled in, but it is still waiting to be sent, so it is first cached here.


Cache receiving is divided into two regions:

A. empty slot: Used to accept data bytes.

B. Received slot: Contains received bytes, which will be read by the receiving process. When a byte is read by the receiving process, the corresponding slot will be recycled into an empty slot.

In a word, we can use the cache mechanism to handle the speed difference between processes generated and consumed.

1.2.2 packet segment

We know that the IP layer provides TCP services to send data in groups rather than byte streams. In this way, at the transport layer, TCP groups several bytes into a packet segment, the length of these packets is not necessarily the same. TCP also adds a header to the packet segment after each group for control, and then delivers the packet segment to the IP layer for transmission. After these packets are encapsulated into IP data packets, they may be out of order, lost, or damaged at the receiving end. This will be handled by TCP. For the receiving process, it does not know these TCP activities.

1.3 Full Duplex Communication

TCP provides full-duplex services, that is, data can flow in two directions at the same time. Because the two TCP endpoints have their own sending cache and receiving cache, the packet segment can be moved in these two directions.

1.4 reuse and reuse

Like UDP, TCP is reused at the sending end and used separately at the receiving end.

1.5 connection-oriented services

Unlike UDP, TCP is a connection-oriented protocol. Each process needs to establish a connection. When one process on Site A and another process on Site B exchange data, it must go through the following three phases:

A. Create a virtual connection between two processes

B. Data Exchange in two directions

C. Connection termination

It should be noted that the connection between the two TCP endpoints is a virtual connection, not a physical connection, but a streaming-oriented environment-a virtual connection, it can deliver these bytes to the destination in order. After a TCP packet segment is encapsulated as an IP datagram, it may be out of order, lost or damaged during transmission and re-transmitted. Each IP datagram can go through different paths to reach the destination.

1.6 reliable services

TCP is a reliable transport protocol that uses a validation mechanism to check whether data is securely delivered.

---------------------------------------------------------------------------------

Ii. TCP features 2.1 Numbering System

There are two fields in the header of the TCP packet segment: serial number and validation number, which refer to the byte number and non-packet segment number.

A. byte number (byte number)

TCP records all data bytes to be sent in a connection. The numbers in both directions are independent of each other. When TCP receives data bytes from the process, that is, when the process is entrusting the data to be sent to TCP, it stores the data in the sending cache and carries out the numbers from 0 ~ A random number starts between the power of 32 and 1. For example, if the random number is 1057 and the total length of sent data is 6000 bytes, the numbers of these bytes will start from 1057 ~ 7056, that is, each byte of the data to be sent is numbered one by one. This numbering mechanism is used in error control and traffic control.

The data transmitted on each connection is numbered by TCP. The number starts from a random number.

B. Serial number

When the bytes are numbered, TCP assigns a serial number to each packet segment to be sent. The serial number of each packet segment is the serial number of the First Data byte of the packet segment. That is, the serial number field value of the packet segment defines the number (byte number) assigned by the First Data byte contained in the packet segment ).

C. Confirmation Number

TCP communication is full-duplex communication. After the connection is established, both parties can send and receive data simultaneously. Generally, both parties start from different start numbers to byte numbers. The serial numbers in each direction represent the numbers of the First Data byte carried by the packet segment in this direction. Both parties also use the confirmation number to confirm their own receipt.

The validation number defines the number of the next byte it expects to receive, similar to the program counter. The validation number is also cumulative, that is, the number of the last safe and sound byte it received plus the value obtained by 1 is declared as the confirmation number. For example, if one party uses 5250 as the confirmation number, it indicates that it has received all the bytes from the start to the number 5249. The next stage is to receive the byte of the number 5250.

In general, the value of the validation field in the packet segment defines the number of the next byte to be received by one party, and the validation number is accumulated.


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.