当前位置:网站首页>What is the difference between TCP and UDP?
What is the difference between TCP and UDP?
2022-07-07 07:34:00 【Bald cat light King】
Classic interview questions TCP and UDP What's the difference? ?
Solve interview questions , Win your favorite OfferList of articles
One 、TCP and UDP What is it? ?
TCP:
Transmission control protocol (TCP,Transmission Control Protocol) It's a connection oriented 、 reliable 、 Transport layer communication protocol based on byte stream , from IETF Of RFC 793 Definition .
UDP:
Internet The protocol set supports a connectionless transport protocol , This protocol is called user datagram protocol (UDP,User Datagram Protocol).UDP Provides an application with a way to send encapsulation without establishing a connection IP The packet approach .RFC 768 It describes UDP.
Two 、TCP and UDP What's the difference? ?
1.TCP and UDP Sum up the difference
TCP And UDP Sum up the difference :
- TCP Connection oriented , Establish a connection with three handshakes , Four waves to receive and remove the connection ;UDP It's disconnected , That is, you don't need to establish a connection before sending data , This way is UDP It brings efficient transmission efficiency , But it also makes it impossible to ensure the successful sending of data .
- TCP Is a reliable means of communication . adopt TCP Connect the transmitted data ,TCP Retransmission via timeout 、 Data verification and other methods to ensure that the data is error free , No loss , No repetition , And arrive in order ; and UDP Because there is no need to connect , Will transmit at maximum speed , But there is no guarantee of reliable delivery , That is, there will be loss 、 Repeat and so on .
- TCP Byte stream oriented , It's actually TCP Think of data as a stream of unstructured bytes , Due to the problem of connection , When the network fluctuates , Connection may have response problems ;UDP It's message oriented ,UDP no congestion control , Therefore, the network congestion will not reduce the transmission rate of the source host .
- Every one of them TCP Connections can only be point-to-point ; and UDP Do not establish a connection , So it can support one-on-one , One to many , Many to one and many to many interactive communication , That is, you can accept multiple people's bags at the same time .
- TCP Connection required , First cost 20 Bytes compared 8 Bytes of UDP It looks big .
- TCP The logical communication channel of is a full duplex reliable channel ,UDP It's an unreliable channel .
2.TCP Three handshakes and four waves
2.TCP Three handshakes
Three handshakes are TCP The way to ensure that the connection is established reliably :
- The first handshake : A to B Text and say :“B, Are you free now? ?”
- The second handshake : B At this time, I received A Information about , Then on A say : “ I'm free , And you? ? Do you have a second? ? ”
- The third handshake : A At this time, I received B The confirmation of , And said, :“ I'm free, too , Let me tell you something .”
After three handshakes ,A and B Can be sure of such a thing : The communication between both parties can be carried out smoothly . such , The two sides can start a normal dialogue .
2.TCP Four waves
Four waves are TCP A way to ensure that the connection is closed reliably :
First wave : A to B Text and say :“B, I'm going to prepare for dinner ?”
Second wave : B At this time, I received A Information about , And then first of all A say : “ I got it! .”
Third wave : B Yes A Speaking of : “ I'm also going to prepare for dinner .” Then put down the phone ,
Fourth wave : A At this time, I received B The confirmation of , And then think B Send a bag and say :“ well , I got it! .” Then I put down my cell phone and went to eat ,
After four waves ,A and B Can be sure of such a thing : The communication between both parties can be closed normally . such , Both parties can make sure that the other party is fully aware of their confirmation to close the connection .
3.TCP Maintain reliable communication mode
- Data fragmentation : Segment the user data at the sending end , Regroup at the receiving end , from TCP Determine the size of the segments and control the fragmentation and recombination ;
- Arrival confirmation : When the receiving end receives the fragmentation data , Send a confirmation packet to the sender according to the fragment data serial number ;
- Timeout retransmission : The sender clocks after sending slices , If the time-out does not receive the corresponding confirmation package , The corresponding fragment will be resend ;
- The sliding window :TCP The receiving buffer space of both sides of the connection is fixed , The receiving end can only accept the data that the buffer can accept .
- Out of order processing :TCP The receiving end of needs to reorder the received data .
- Reprocessing : If the transmitted TCP Repeat in pieces ,TCP The receiving end of needs to discard duplicate data .
- data verification :TCP Detect any changes in the data during transmission by maintaining the checksum of its header and data .
4.TCP and UDP Use scenarios
1.UDP Use scenarios :
therefore UDP No complex control mechanism , utilize IP Provide connectionless communication services , Data can be sent at any time , Simple and efficient processing .
So it is mainly used in the following scenarios :
- Communications with a small total number of packets (DNS、SNMP)
- video 、 Audio and other multimedia communication ( Instant messaging )
QQ It is used UDP agreement . - Broadcast communications
Mainly in all the scenes of pursuing speed
2.TCP Use scenarios :
TCP Use scenarios : be relative to UDP,TCP Various controls in the process of data transmission are realized , Retransmission control during packet loss can be performed , It can also control the order of the disordered subcontracting . In the case of high reliability requirements , have access to TCP, That does not consider UDP When , You can choose TCP.
In particular, reliable connection is required , Like paying 、 Encrypting data and other directions need to rely on TCP
summary
Connection oriented TCP And disconnected UDP It will be an indispensable and important knowledge point in Network Protocol ,TCP and UDP yes TCP/IP There are two representative transport layer protocols , It is also a perennial test question type .
I hope this blog will be beneficial to you . I am the light king , I represent myself. .边栏推荐
- I failed in the postgraduate entrance examination and couldn't get into the big factory. I feel like it's over
- 软件验收测试
- Wechat applet full stack development practice Chapter 3 Introduction and use of APIs commonly used in wechat applet development -- 3.9 introduction to network interface (IX) extending the request3 met
- Détailler le bleu dans les tâches de traduction automatique
- 科技云报道:从Robot到Cobot,人机共融正在开创一个时代
- 詳解機器翻譯任務中的BLEU
- 点亮显示屏的几个重要步骤
- 2、 Concurrent and test notes youth training camp notes
- 云备份项目
- Asynchronous components and suspend (in real development)
猜你喜欢

Bindingexception exception (error reporting) processing

Pass parent component to child component: props

Robot technology innovation and practice old version outline
![[2022 CISCN]初赛 web题目复现](/img/1c/4297379fccde28f76ebe04d085c5a4.png)
[2022 CISCN]初赛 web题目复现

抽丝剥茧C语言(高阶)指针进阶练习

4、 High performance go language release optimization and landing practice youth training camp notes

Nesting and splitting of components

L'étape avancée du pointeur de langage C (haut de gamme) pour l'enroulement des cocons

Apache AB stress test

The metauniverse of the platofarm farm continues to expand, with Dao governance as the core
随机推荐
考研失败,卷不进大厂,感觉没戏了
软件验收测试
Differences between H5 architecture and native architecture
1、 Go knowledge check and remedy + practical course notes youth training camp notes
URP - shaders and materials - light shader lit
Readonly read only
三、高质量编程与性能调优实战 青训营笔记
PostgreSQL source code (59) analysis of transaction ID allocation and overflow judgment methods
Fullgc problem analysis and solution summary
Cloud backup project
Summary of customer value model (RFM) technology for data analysis
計算機服務中缺失MySQL服務
按键精灵脚本学习-关于天猫抢红包
95后CV工程师晒出工资单,狠补了这个,真香...
身边35岁程序员如何建立起技术护城河?
Communication of components
[semantic segmentation] - multi-scale attention
How to * * labelimg
3、 High quality programming and performance tuning practical youth training camp notes
MobaXterm