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

Differences and usage scenarios between TCP and UDP

2022-07-06 02:32:00 Xiao Wang's shell is quite hard

difference :


1. Connect
TCP yes ⾯ The transport layer protocol for the connection , Before transmitting data, it is necessary to build ⽴ Connect .
UDP It doesn't need to be connected , Instant transmission of data .


2. service object
TCP yes ⼀ Yes ⼀ Our two services , namely ⼀ A connection has only two endpoints .
UDP ⽀ a ⼀ Yes ⼀、⼀ For more than 、 Many to many interactive communication


3. reliability
TCP Reliable delivery of data , Data can ⽆ A mistake 、 No loss 、 No repetition 、 On demand arrival .
UDP Is the most ⼤ No ⼒ deliver , Reliable delivery of data is not guaranteed .


4. Congestion control 、 flow control
TCP There are congestion control and flow control mechanisms , Ensure the security of data transmission .
UDP There is no , Even if ⽹ Collateral ⾮ It's often congested , It won't affect UDP The transmission rate of .


5. ⾸ Department expenses
TCP ⾸ Ministry ⻓ The degree is ⻓, There will be ⼀ Fixed expenses ,⾸ The Ministry did not make ⽤「 Options 」 Field is 20 Bytes , If so ⽤ 了 「 Options 」 The field will change ⻓ Of .
UDP ⾸ There are only 8 Bytes , And it's fixed , It costs more ⼩.


6. transmission ⽅ type
TCP It's streaming , There is no boundary , But ensure sequence and reliability .
UDP yes ⼀ A package ⼀ Sending packets , There are boundaries , But there may be packet loss and disorder .


7. branch ⽚ Different
TCP The data of ⼤⼩ If ⼤ On MSS ⼤⼩, It will enter... At the transport layer ⾏ branch ⽚,⽬ After the bid host receives it , It is also assembled at the transport layer TCP Data packets , If you lose it halfway ⼀ A minute ⽚, Only need to transmit the lost points ⽚.
UDP The data of ⼤⼩ If ⼤ On MTU ⼤⼩, Will be in IP Step into ⾏ branch ⽚,⽬ After the bid host receives it , stay IP Layer assembled data , Then it is transmitted to the transport layer , But if you lose it halfway ⼀ A minute ⽚, In order to realize reliable transmission UDP Then you need to transmit all data packets , In this way, the transmission efficiency ⾮ Constant difference , So usually UDP The newspaper ⽂ should ⼩ On MTU.

Use scenarios :

TCP

because TCP yes ⾯ Connect to , It can ensure the reliable delivery of data , So often ⽤ On :
FTP ⽂ Piece transmission
HTTP / HTTPS

UDP
because UDP ⾯ towards ⽆ Connect , It can send data at any time , Plus UDP The process itself is simple ⼜⾼ effect , So often ⽤ On :
Less total packets of communication , Such as DNS 、 SNMP etc. 、 video 、⾳ Frequency and other multimedia communication 、⼴ Broadcast communications

原网站

版权声明
本文为[Xiao Wang's shell is quite hard]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140015016280.html