当前位置:网站首页>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. .边栏推荐
- Detailed explanation of transform origin attribute
- 1142_ SiCp learning notes_ Functions and processes created by functions_ Linear recursion and iteration
- 抽絲剝繭C語言(高階)指針的進階
- Talk about seven ways to realize asynchronous programming
- 虚拟机的作用
- 1、 Go knowledge check and remedy + practical course notes youth training camp notes
- Simple example of ros2 planning system plansys2
- 四、高性能 Go 语言发行版优化与落地实践 青训营笔记
- A concurrent rule verification implementation
- Stockage et pratique des données en langage C (haut niveau)
猜你喜欢

弹性布局(二)

Outlier detection technology of time series data

外包干了四年,废了...

考研失败,卷不进大厂,感觉没戏了

Detailed explanation of transform origin attribute

Dynamics CRM server deployment - restore database prompt: the database is in use

Apache AB stress test

Wechat applet full stack development practice Chapter 3 Introduction and use of APIs commonly used in wechat applet development -- 3.10 tabbar component (I) how to open and use the default tabbar comp

Stockage et pratique des données en langage C (haut niveau)

弹性布局(一)
随机推荐
Torefs API and toref API
MIPS uclibc cross compile ffmpeg, support g711a encoding and decoding
At the age of 20, I got the ByteDance offer on four sides, and I still can't believe it
URP - shaders and materials - light shader lit
Outsourcing for four years, abandoned
外包幹了三年,廢了...
MobaXterm
../ And/
Implementing data dictionary with JSP custom tag
Interviewer: what development models do you know?
Kuboard无法发送邮件和钉钉告警问题解决
Talk about seven ways to realize asynchronous programming
"Xiaodeng in operation and maintenance" meets the compliance requirements of gdpr
English translation is too difficult? I wrote two translation scripts with crawler in a rage
詳解機器翻譯任務中的BLEU
JS small exercise
07_ Handout on the essence and practical skills of text measurement and geometric transformation
身边35岁程序员如何建立起技术护城河?
抽絲剝繭C語言(高階)數據的儲存+練習
虚拟机的作用