Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

TCP and UDP protocol

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

There are two main transport layer protocols: TCP (Transmission Control Protocol) and UDP (user Datagram Protocol).

Let's take a detailed look at TCP and UDP.

1. TCP protocol

TCP protocol introduction: TCP is a connection-oriented, reliable process-to-process communication protocol. TCP provides duplex full-time service, that is, data can be transmitted in both directions at the same time, and each TCP has a send cache and a receive cache, which are used to store data on a temporary basis.

TCP message paragraph:

TCP groups several bytes into a packet, called a message segment. The header format of the TCP message paragraph is shown in the following figure.

Source port number: the port number corresponding to the sender.

Destination port number: the port number of the receiver, which is used by the receiver to determine which application to send data to.

Serial number: TCP numbers the bytes received from the process so that when the data reaches the receiver, the receiver can reorganize the data according to Yu Hao to ensure the correctness of the data.

Confirmation number: the confirmation number is for the sender to confirm the message, and it tells the sender that all the data prior to this serial number has been received.

Header length: the length of the header data structure.

Reserved: this feature has not been used yet, and will be reserved for future expansion.

UGR: emergency pointer valid bits that can be passed directly to the application without caching.

ACK: confirm the sign, make sure that the flag bar is valid.

PSH: a flag bit of 1 requires the receiver to deliver the data segment to the application layer as soon as possible, but it still needs to be cached.

RST: re-establish the TCP connection.

SYN: establish a TCP connection.

FIN: disconnect the TCP connection.

Window value: the number of segments that can be received locally. The size of this value is variable. The higher the window value, the faster the transmission rate, and vice versa.

Checksum: used for error control. If the check result of the receiver is consistent with that of the sender, the data is correct. Otherwise, the data is corrupted and the receiver will discard the data.

Emergency pointer: used with URG.

Options: optional information for the TCP header, such as when the data was created.

TCP connection

The process of establishing a connection in TCP is also known as the TCP three-way handshake.

First handshake: when establishing a connection, the client sends a syn packet (syn=j) to the server, enters the SYN_SENT state, and waits for the server to confirm.

Second handshake: when the server receives the syn packet, it must confirm the customer's SYN (ack=j+1) and send itself a SYN packet (seq=k), that is, the SYN+ACK packet.

Third handshake: the client receives the SYN+ACK packet from the server and sends an acknowledgement packet ACK (ack=k+1) to the server.

The three-way handshake is complete, and the client and server enter a successful TCP connection state. At this point, the client and the server can transfer data to each other.

Of course, this process can also be seen as the establishment of a dialogue between two people.

First handshake A: is so-and-so here?

Second handshake B: yes, what can I do for you?

Third handshake A: what am I looking for you?

Of course, we may not be able to fully express the TCP three-way handshake in detail, but we can look at the process in this way to facilitate our understanding.

TCP connection termination

Either party participating in a data connection can close the connection, and TCP disconnection is also known as the TCP four-way handshake.

First handshake: the active interrupt sends the TCP message segment of FIN and ACK location 1 to the other party.

Second handshake: the passive side returns the TCP segment of ACK position 1 in the direction of the active disconnect.

Third handshake: passively sends the TCP message segment of FIN and ACK position 1 to the party that is actively disconnected.

Fourth handshake: the active disconnected party returns the TCP message segment of ACK position 1 to the other party.

Why does it take only three steps to set up a TCP but four steps to disconnect it?

Because if An and B want to disconnect, then A will send FIN,B to B and will reply ACK after receiving, but it is possible that B still has data transmission not completed, so ACK and FIN did not reply to A together, wait until B's data transmission is completed, will send FIN to A Magi A to receive B's FIN reply ACK then both sides will disconnect, which is why disconnection is one more step than establishment.

TCP Port and its Application

UDP protocol

UDP is a connectionless and reliable transmission protocol. Both it and TCP are in the transport layer. Although it can not guarantee reliability, it has low delay and high data transmission efficiency in the process of data transmission.

The format of the head of UDP

Source port number: used to identify the process on the sending side.

Destination port number: used to identify the receiving end process.

UDP length: represents the total length of the UDP.

Checksum: used to check for errors in UDP data.

UDP Port and its Application

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report