UDP ------ Comparison of UDP and TCP

UDP is a connectionless protocol, and there is no need to establish a handshake connection before the client and server communicate;

UDP does not have a response mechanism, so there is no retransmission mechanism, which may cause packet loss, repeated packets, and disorder;

UDP can realize the LAN broadcast function, that is, a host can send data to all hosts in the same subnet, while TCP cannot broadcast, only unicast;

TCP is a connection protocol, and the client needs three handshakes before sending data to the server;

TCP has a retransmission mechanism. When the data is transmitted from the A side to the B side, the B side will send an acknowledgment packet (ACK packet) to the A side to inform the A side that I have received the data! There is a retransmission mechanism, and the A side does not receive the confirmation packet and will resend it;

 

 When the network is poor to a certain extent, the advantage of TCP will become a disadvantage. For example, the client and the server need to make frequent connections and retransmit. UDP has less intervention on the application layer and is more flexible, and can solve the problems that TCP presents when the network is poor.

When the real-time requirements are relatively high, it must be udp, because a large amount of data is transmitted in real-time, and some packets are lost without hindering the real-time performance;

If the network is very good, and the data is complete, it can only be said to give priority to tcp, udp can also be done, but it is more troublesome to do the verification and judgment of the unpacked and subpackaged frames, but it is absolutely Better than tcp, this is when the company's human resources allow; 

Therefore, to sum up the above: udp is given priority for the transmission of the external network, only udp can be used for high real-time performance, and tcp development is relatively simple, which can be considered for development efficiency;

If it is a local area network transmission, don't even think about using tcp, whether it is real-time or large files use tcp, because the network speed of the local area network is not questioned;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324827565&siteId=291194637