TCP and UDP difference

TCP connection is established

If someone asks how to establish a TCP connection? Most of the answer is three-way handshake is successful, a connection is established.

So what is the purpose of a handshake is it?

1) inform each other of their own number

2) initialization resources

For example the following cases handshake, the handshake twice initiative initiated by the client, once initiated by the server.

TCP three-way handshake

 

Handshake steps:

1) The client sends a TCP packet to the server, the server notifies the client ID is X.

2) the server sends an acknowledgment reply to the client, notify the client has received the information.

3) the server sends its serial number to the client, tell each other their number is Y.

4) The client back to confirm information confirming the server's serial number has been received.

 

In fact, 2) and 3) These two steps can be combined into one step, two steps of the same information in a TCP data package.

 

UDP packet transmission

UDP protocol is not connection-oriented protocol. So UDP packets do not need three-way handshake, you do not need to be connected. UDP packet is disordered, and TCP packets are ordered.

1,2,3 TCP packet sequence number sent, TCP packet receiving terminal will also receive sorted 1,2,3 package, but the package will receive UDP packets out of order.

 

Differences in the

When TCP data transmission, due to the need for three-way handshake, so no good real-time UDP. UDP communications in real-time to do better, UDP packet loss does not affect the next transmission, real-time video screen appears little impact on the overall loss of video, fulfill the functions of real-time transmission. But after the TCP packet loss, repeatedly sends packets are lost, it will cause a lot of repetition, the video may be Caton.

 

However, in other applications, if there is no real-time requirements, TCP is the first choice for sure.

Guess you like

Origin www.cnblogs.com/gzhich2019/p/11846062.html