当前位置:网站首页>Differences between TCP and UDP

Differences between TCP and UDP

2022-06-26 04:40:00 Half crazy and half bumpy

Common seven story application diagram :

 

1. TCP Connection process ( Three handshakes )

As shown in the figure below , You can see to create a TCP The process of connection is ( Three handshakes ):

 

The first handshake

The client sends the connection request message segment to the server . The message segment contains its own initial data communication serial number . After the request is sent , The client enters SYN-SENT state .

The second handshake

After the server receives the connection request message segment , If you agree to connect , A response will be sent , The response will also contain its own initial data communication serial number , After sending, enter SYN-RECEIVED state .

The third handshake

When the client receives the reply of the connection consent , Also send a confirmation message to the server . After the client sends this message segment, it will enter ESTABLISHED state , After receiving this response, the server will enter ESTABLISHED state , At this time, the connection is established successfully .

There may be a doubt here : Why? TCP Establishing a connection requires three handshakes , Not twice ? This is to prevent the invalid connection request message segment from being received by the server , So there's a mistake .

2.TCP break link ( Four waves )

 

TCP It's full duplex , Both ends need to send... When disconnected FIN and ACK.

The first handshake

If the client A Think data transmission is complete , Then it needs to go to the server B Send connection release request .

The second handshake

B After receiving the connection release request , Will tell the application layer to release TCP link . Then it will send ACK package , And enter CLOSE_WAIT state , At this point, it means A To B The connection of has been released , No longer receive A Data sent . But because TCP The connection is two-way , therefore B You can still send data to A.

The third handshake

B If there is still unfinished data at this time, it will continue to send , When it's done, I'll go to A Send connection release request , then B Then enter LAST-ACK state .

The fourth handshake

A After receiving the release request , towards B Send a confirmation response , here A Get into TIME-WAIT state . This state will last 2MSL( The maximum survival period , It refers to the time of message segment in the network , Overtime will be abandoned ) Time , If there is no B If you want to resend the request , To get into CLOSED state . When B After receiving the confirmation reply , And then I went into CLOSED state .

TCP and UDP The difference between

Refer to the below

summary :

  • TCP Provide reliable connection oriented services to the upper layer ,UDP Provide connectionless and unreliable services to the upper layer .
  • although UDP did not TCP The transmission is accurate , But it can also make a difference in many places with high real-time requirements
  • High requirements for data accuracy , The speed can be relatively slow , May choose TCP

 

 

原网站

版权声明
本文为[Half crazy and half bumpy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180510567841.html