search
HomeWeb Front-endHTML TutorialWhat is the difference between TCP/IP and UDP?

What is the difference between TCP/IP and UDP?

Sep 07, 2017 pm 01:58 PM
tcp/ipudpthe difference

TCP (Transmission Control Protocol)

is a connection-oriented protocol, that is to say, before sending and receiving data, it must Establish a reliable connection with the other party. A TCP connection must go through three "conversations" before it can be established

TCPThree-way handshakeProcess:

1 Host A sends a data segment containing the flag bit of the synchronization sequence number to Host B and requests Host B to establish a connection. Through this data segment, Host A tells Host B two things: I want to I want to communicate with you; which sequence number can you use as the starting data segment to respond to me.

2 Host B, after receiving the request from Host A, responds with a confirmation ( The data segment with ACK) and synchronization sequence number (SYN) flags responds to host A and tells host A two things: I have received your request and you can transmit data; which sequence number do you want to use as the starting point? The first data segment to respond to me

3 After host A receives this data segment, it sends a confirmation response to confirm that it has received the data segment from host B: "I have received the reply , I am now going to start transmitting actual data

In this way, the three-way handshake is completed, and host A and host B can transmit data.

Characteristics of the 3-way handshake:

1) No application layer data

2) SYN flag The bit will only be set to 1 when TCP establishes a connection

3) The SYN flag is set to 0 after the handshake is completed

TCP requires 3 handshakes to establish a connection, while requires 4 handshakes to disconnect

##1 When host A completes the data transmission, it will control The FIN bit is set to 1, making a request to stop the TCP connection

2 Host B responds to the FIN after receiving it, confirms that the TCP connection in this direction will be closed, and sets ACK to 1

3 The B-side makes another close request in the opposite direction, sets FIN to 1

4 Host A confirms Host B’s request, sets ACK to 1, and the two-way shutdown ends.

It can be seen from TCP’s three-way handshake and four disconnections that TCP The use of connection-oriented communication greatly improves the reliability of data communication, allowing the sending data end and the receiving end to interact before the data is officially transmitted, laying a reliable foundation for the formal data transmission

Explanation of terms

ACK - One of the control bits in the TCP header, which confirms the data. The confirmation is sent by the destination, and is used to tell The sender has received all the data segments before the sequence number. For example, if the confirmation number is , the confirmation number is invalid, then the data will be required to be retransmitted to ensure the integrity of the data.

SYN——Synchronization sequence number, set this position to 1 when TCP establishes a connection

FIN——The sender has completed the sending task bit. When TCP completes the data transmission and needs to be disconnected, the party that proposes to disconnect will set this bit to 1

TCP header structure:

Source port 16 bits

Destination port 16 bits

Sequence number 32 bits

Response sequence number 32 bits

TCP header length 4 bits

reserved 6 digits

Control code 6 digits

Window size 16 digits

Offset 16 bits

Checksum 16 bits

Option 32 bits (optional)

In this way we get the minimum length of the TCP header, which is 20 bytes.

UDP (User Data Protocol, User Datagram Protocol)

(1) UDP is a non-connection protocol. The source and terminal do not establish a connection before transmitting data. When it wants to transmit, it simply grabs the data from the application and transmits it as quickly as possible. Throw it on the web. On the sending end, the speed at which UDP transmits data is only limited by the speed at which the application generates data, the computer's capabilities, and the transmission bandwidth; at the receiving end, UDP puts each message segment in a queue, and the application reads each message segment from the queue each time. Read a message segment.

(2) Since no connection is established when transmitting data, there is no need to maintain the connection status, including sending and receiving status, etc. Therefore, a server machine can transmit the same data to multiple clients at the same time. news.

(3) The header of the UDP packet is very short, only 8 bytes. Compared with the 20-byte packet of TCP, the additional overhead is very small.

(4) Throughput is not regulated by the congestion control algorithm and is only limited by the rate of data generated by the application software, transmission bandwidth, and source and terminal host performance.

(5) UDP uses best-effort delivery, that is, reliable delivery is not guaranteed, so the host does not need to maintain a complex link state table (there are many parameters in it).

(6) UDP is message-oriented. The message handed over by the sender's UDP to the application program is delivered down to the IP layer after adding a header. Neither splitting nor merging is done, but the boundaries of these packets are preserved, so the application needs to choose an appropriate packet size. We often use the "ping" command to test whether the TCP/IP communication between two hosts is normal. In fact, the principle of the "ping" command is to send a UDP data packet to the other host, and then the other host confirms receipt of the data packet. If the data packet is If the arriving news is fed back in time, the network will be open.

UDP header structure:

##Source port 16 bits

Destination port 16 bits

Length 16 bits

Checksum 16 bits

Summary of the difference between TCP and UDP:

1. Based on connection and connectionless;

2. On system resources Requirements (more TCP, less UDP);

3. UDP program structure is relatively simple;

4. Stream mode and datagram mode ;

5.TCP guarantees data correctness, UDP may lose packets, TCP guarantees data order, but UDP does not.

The above is the detailed content of What is the difference between TCP/IP and UDP?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
HTML: Is It a Programming Language or Something Else?HTML: Is It a Programming Language or Something Else?Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The Role of HTML: Structuring Web ContentThe Role of HTML: Structuring Web ContentApr 11, 2025 am 12:12 AM

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTML and Code: A Closer Look at the TerminologyHTML and Code: A Closer Look at the TerminologyApr 10, 2025 am 09:28 AM

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS, and JavaScript: Essential Tools for Web DevelopersHTML, CSS, and JavaScript: Essential Tools for Web DevelopersApr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesThe Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesApr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment