Both are communication protocols. TCP and UDP are transport layer protocols, but their communication mechanisms are different from the application scenarios. The differences between the two and their application scenarios are described below.
TCP and UDPTCP (Transmission Control Protocol), also known as Transmission Control Protocol, UDP (User Datagram Protocol), also known as User Datagram Protocol, are all transport layer protocols, but the mechanisms of the two are different, and their differences are as follows:
As seen from the above table, TCP is connection-oriented and is a reliable protocol. When communicating based on TCP, the two parties need to establish a TCP connection first. After the connection is established, the handshake must be performed three times. Please refer to this article for the process of TCP three-way handshake and four wave hands.
In addition, the TCP protocol is a reliable transmission protocol, so how does it guarantee reliability?
reliability
Before explaining how TCP guarantees reliability, you must first understand what is reliable. From the perspective of communication, reliability is to ensure that the communication information of both parties is not lost. If it is lost, it can be recovered, and the content of the received information is the same as the original content.
In TCP, the transmitted packets are transmitted through the established virtual connection. Each TCP packet transmitted by the sender is numbered. The number is due to network transmission, and the sent packets may be out of order. Arrival, therefore, the message needs to be rearranged according to the number), and a timer is started; when the receiving end receives the message, and the check packet data is verified by the checksum, if the verification succeeds It will return an acknowledgement message to inform the sender that I have successfully received the message. If the sender does not receive the acknowledgement message before the timer expires, it will be retransmitted if the receiver fails to receive the message. If the server receives a duplicate packet (it is already received according to the number), the server discards the packet.
Therefore, it can be known from the above mechanism that TCP is reliable by means of retransmission, acknowledgment and checksum.
Advantages of Tcp:Reliable and stable
The reliability of TCP is reflected in the three-way handshake to establish the connection (four wave release connection) before the data is transmitted, and there are confirmation, window, retransmission, and congestion control mechanisms when the data is transmitted. After the data is transmitted, the connection is disconnected. Save system resources.
The disadvantages of TCPSlow, low efficiency, high system resources, easy to be attacked
Establishing a connection before passing data takes time, and the acknowledgment mechanism, retransmission mechanism, and congestion control mechanism consume a lot of time during message delivery, and all transport connections are maintained on each device. Each connection will occupy hardware and software resources such as the system's CPU and memory. And TCP's access mechanism, three-way handshake, which also makes TCP easy to be used, to achieve DOS, DDOS attacks.
Advantages of UDPFaster, slightly safer than TCP
UDP does not have TCP handshake, acknowledgment, window, retransmission, congestion control, etc. udp is a stateless transport protocol, so he is very fast when transmitting data. M does not have these mechanisms of TCP. UDP is less vulnerable to exploits than TCP. UDP is also unavoidable, such as UDP flood attacks. . .
Disadvantages of UDPUnreliable, unstable
Because UDP does not have the reliable mechanism of TCP, it is easy to lose packets when the network quality is not good.
Based on the above advantages, then:  
UDP is a connection-free and unreliable protocol. In the process of communication, it does not need to establish a connection like TCP. As long as (destination address, port number, source address, port number) is determined, you can The message is sent directly, and there is no need to ensure that the server will receive or receive the complete data. It only provides a checksum mechanism to ensure that a packet is complete. If the check fails, the packet is discarded directly without any processing.
RAM/RFM electric heating capacitors
RAM/RFM electric heating capacitors
Electric Heating Capacitor,Film Heating Capacitor,Electric Capacitor Bank,Induction Heating Capacitors
YANGZHOU POSITIONING TECH CO., LTD , https://www.yzpstcc.com