Home Web Front-end HTML Tutorial What 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/ip udp the 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 of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the basic requirements for c language functions What are the basic requirements for c language functions Apr 03, 2025 pm 10:06 PM

C language functions are the basis for code modularization and program building. They consist of declarations (function headers) and definitions (function bodies). C language uses values ​​to pass parameters by default, but external variables can also be modified using address pass. Functions can have or have no return value, and the return value type must be consistent with the declaration. Function naming should be clear and easy to understand, using camel or underscore nomenclature. Follow the single responsibility principle and keep the function simplicity to improve maintainability and readability.

How to set password protection for export PDF on PS How to set password protection for export PDF on PS Apr 06, 2025 pm 04:45 PM

Export password-protected PDF in Photoshop: Open the image file. Click "File"> "Export"> "Export as PDF". Set the "Security" option and enter the same password twice. Click "Export" to generate a PDF file.

Concept of c language function Concept of c language function Apr 03, 2025 pm 10:09 PM

C language functions are reusable code blocks. They receive input, perform operations, and return results, which modularly improves reusability and reduces complexity. The internal mechanism of the function includes parameter passing, function execution, and return values. The entire process involves optimization such as function inline. A good function is written following the principle of single responsibility, small number of parameters, naming specifications, and error handling. Pointers combined with functions can achieve more powerful functions, such as modifying external variable values. Function pointers pass functions as parameters or store addresses, and are used to implement dynamic calls to functions. Understanding function features and techniques is the key to writing efficient, maintainable, and easy to understand C programs.

The difference between H5 and mini-programs and APPs The difference between H5 and mini-programs and APPs Apr 06, 2025 am 10:42 AM

H5. The main difference between mini programs and APP is: technical architecture: H5 is based on web technology, and mini programs and APP are independent applications. Experience and functions: H5 is light and easy to use, with limited functions; mini programs are lightweight and have good interactiveness; APPs are powerful and have smooth experience. Compatibility: H5 is cross-platform compatible, applets and APPs are restricted by the platform. Development cost: H5 has low development cost, medium mini programs, and highest APP. Applicable scenarios: H5 is suitable for information display, applets are suitable for lightweight applications, and APPs are suitable for complex functions.

Why do you need to call Vue.use(VueRouter) in the index.js file under the router folder? Why do you need to call Vue.use(VueRouter) in the index.js file under the router folder? Apr 05, 2025 pm 01:03 PM

The necessity of registering VueRouter in the index.js file under the router folder When developing Vue applications, you often encounter problems with routing configuration. Special...

What are the differences and connections between c and c#? What are the differences and connections between c and c#? Apr 03, 2025 pm 10:36 PM

Although C and C# have similarities, they are completely different: C is a process-oriented, manual memory management, and platform-dependent language used for system programming; C# is an object-oriented, garbage collection, and platform-independent language used for desktop, web application and game development.

How to use XPath to search from a specified DOM node in JavaScript? How to use XPath to search from a specified DOM node in JavaScript? Apr 04, 2025 pm 11:15 PM

Detailed explanation of XPath search method under DOM nodes In JavaScript, we often need to find specific nodes from the DOM tree based on XPath expressions. If you need to...

What are the different ways of promoting H5 and mini programs? What are the different ways of promoting H5 and mini programs? Apr 06, 2025 am 11:03 AM

There are differences in the promotion methods of H5 and mini programs: platform dependence: H5 depends on the browser, and mini programs rely on specific platforms (such as WeChat). User experience: The H5 experience is poor, and the mini program provides a smooth experience similar to native applications. Communication method: H5 is spread through links, and mini programs are shared or searched through the platform. H5 promotion methods: social sharing, email marketing, QR code, SEO, paid advertising. Mini program promotion methods: platform promotion, social sharing, offline promotion, ASO, cooperation with other platforms.

See all articles