Protocols of the TCO/IP protocol suite (TCP, UDP), transport layer protocol

One, TCP (Transmission Control Protocol) transmission control protocol

TCP is a connection-oriented and reliable protocol for process-to-process communication ( port to port )

The connection-oriented network protocol refers to the establishment of a connection between the communicating parties before communicating. For example, when making a call, the two parties need to establish a connection before talking.

The connectionless network protocol means that the communication parties do not need to establish a communication line in advance, but send each packet with a destination address to the network line, and the system independently selects the route for transmission. For example, QQ and WeChat send messages.

TCP provides full-duplex services , that is, data can be transmitted in both directions at the same time. Each TCP has a sending buffer and a receiving buffer to temporarily store data.

1.1 TCP message

TCP segment: 1. TCP composes several bytes into a group, called segment. 2. TCP segment is encapsulated in IP datagram

### Diagram

### Diagram

Sequence number : the sender will number each byte to facilitate the correct reassembly of the receiver

When TCP receives data bytes from the process, it divides them into data segments and stores them in the sending buffer, and numbers each byte. When the data reaches the destination, the receiving end will rearrange the data according to this sequence number. Ensure the correctness of the data.

Confirmation number : used to confirm the information of the sender

When the receiver responds to the message, it will be used to tell the sender that the data segment before the sequence number has been received. If the confirmation number is x, it means that the first x-1 data have been received.

Header length : Use it to determine the byte length of the TCP header data structure. Under normal circumstances, the TCP header is 20 bytes, but the length of the header can be extended to 60 bytes at most.

Control bit :

URG : Emergency bit ( sender ). The emergency pointer is valid.

ACK : Acknowledge bit (a guarantee). Only when ACK=1, the confirmation sequence number field is valid; when ACK=0, the confirmation number field is invalid.

PSH : Urgent bit. When the flag bit is 1, the receiver is required to deliver the data segment to the application layer as soon as possible.

RST : Reset bit. When the RST value is 1, it is notified to re-establish the TCP connection .

SYN : Synchronization ( connection ) bit. Synchronization sequence number bit, set this value to 1 when TCP needs to establish a connection.

FIN : Disconnect bit. When TCP completes data transmission and needs to disconnect, the party that proposes to disconnect will set this value to 1.

Window size : used for error control. The scope of field checking includes two parts: header and data. The data segment will be checked and calculated when it is sent and when it reaches the destination. If the two checksums are the same, the data is basically correct. Otherwise, the data will be considered corrupted and the receiving end will discard it. data.

Checksum : used for error control. The scope of field checking includes two parts: header and data. The data segment will be checked and calculated when it is sent and when it reaches the destination. If the two checksums are the same, the data is basically correct. Otherwise, the data will be considered corrupted and the receiving end will discard it. data.

Emergency pointer : used in conjunction with URG, valid when URG=1.

Option : There can be up to 40 bytes of optional information in the TCP header. For example, the maximum segment length MSS. MSS tells the TCP: "The maximum length of the data field of the message segment that my buffer can receive is MSS bytes."

1.2 TCP three-way handshake (the process of TCP establishing a connection)

### Diagram

1.3 TCP waved four times (TCP disconnection process)

### Diagram
In the process of TCP disconnection, there is a half-close concept. The TCP side (usually the client) can stop sending data, but can still receive data, which is called a half-close.
Insert picture description here

1.4 Commonly used TCP port numbers and their functions

### Diagram

2. UDP (User Datagram Protocol) User Datagram Protocol

UDP protocol is connectionless , it does not guarantee the reliability of the transport layer protocol . The sender does not care whether the sent data arrives at the destination host, whether the data is wrong, etc. The host receiving the data will not tell the sender whether the data is received, and its reliability is guaranteed by the upper layer protocol. Data transmission is faster , more efficient , and less expensive .

2.1 UDP message

### Diagram

1. UDP length: used to indicate the total length of UDP, and add data to the header.

2. Checksum: used to complete the error check of UDP data, it is the only reliable mechanism provided by the UDP protocol.

2.2 Commonly used UDP port numbers and their functions

### Diagram

Guess you like

Origin blog.csdn.net/IvyXYW/article/details/109278780