Detailed TCP and UDP protocol

One, TCP protocol

In the TCP/IP protocol stack, the transport layer has two protocols: TCP (Transmission Control Protocol) and UDP (User Datagram Protocol).

  • TCP protocol transmission is more stable and reliable, and UDP protocol transmission efficiency is higher. These two protocols have their own characteristics. In actual applications
    , different transport layer protocols can be selected according to the needs of actual applications. For example, services that require high reliability, such as Web and mailboxes, all use the TCP protocol for transmission;
    for instant messaging, DHCP and other services that require fast information transmission, they use the UDP protocol for transmission.
  • TCP is a connection-oriented, reliable process-to-process communication protocol. 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 store data temporarily
    Insert picture description here

Two, six control positions:

URG: Emergency position. Urgent pointer valid bit

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

PSH: Urgent position. 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. The number of data segments. The size of this value is variable,

Three, TCP three-way handshake and four waved hands

Three handshake
Insert picture description here
Wave four times
Insert picture description here

Four, UDP protocol

Compared with the TCP protocol, UDP is a connectionless and reliable transport layer protocol. That is to say, the sender
does not care whether the sent data reaches the target host, whether the data is wrong, etc., and the host receiving the data does not Tell the sender
whether the data is received, and its reliability is guaranteed by the upper layer protocol. Since UDP has such shortcomings, why are processes still
willing to use it? Because UDP also has advantages, UDP has a simple header structure and can achieve minimal overhead during data transmission.
If a process wants to send very short messages and does not care about reliability, UDP can be used. When using UDP to send very short messages,
the interaction between the sender and the receiver is much less than when using TCP.
Therefore, compared to the TCP protocol, UDP transmits data faster and more efficiently.
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_51468875/article/details/114021039