socket programming twenty-five: UDP and TCP talk

TCP is a connection-oriented transport protocol to establish a connection to go through a three-way handshake, to go through the four-way handshake when disconnected, but also to respond to the ACK packet to confirm the intermediate transfer data, a variety of mechanisms to ensure that the correct data can reach, is not lost or error.

UDP transport protocol is disconnected, it no connection and disconnection procedures, it is simply thrown into the data network, you do not need an ACK packet to confirm.

UDP data transfer parcel if we need to fill out before mailing the sender and recipient addresses, and then sent to the courier company, but wrapped properly served, we do not know whether the damage can not be guaranteed. UDP protocol, too, it just sends the packet to the network, and then on the matter, if data is lost or damaged, the sender can not know, of course, will not be re-issued.

That being the case, TCP should be more high-quality transmission protocol, right?

If you only consider the reliability, TCP is indeed better than the UDP. However, UDP is structurally more simple than TCP, it will not send an ACK response message, nor will the packet sequence number Seq distribution, transmission efficiency UDP sometimes much higher than TCP, UDP programming to achieve simpler than TCP.

Although they are not reliable UDP TCP, but it would be data corruption occurs frequently as the imagination, in the case of transmission efficiency rather than greater emphasis on reliability, UDP is a good choice. Such as video communication or audio communication, it is very suitable for UDP protocol; communications data must be efficient transmission will not have a "Caton" phenomenon, the user experience was more fluent, if you lose a few packets, video picture may appear 'snowflakes "audio may be entrained in a number of noise, these are nothing wrong.

Compared with UDP, TCP's life is flow control, which ensures the accuracy of data transmission.

Finally, it should be noted that: TCP speed can not exceed UDP, but there may be close in the UDP send and receive certain types of data. For example, each time the greater the amount of data exchange, the closer UDP TCP transmission rate.

Published 33 original articles · won praise 30 · views 20000 +

Guess you like

Origin blog.csdn.net/baidu_15547923/article/details/90230486