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!

UDP常用端口号有53、69、161、2049、68、520。UDP使用端口号为不同应用保留各自数据传输通道:1、网络文件系统(NFS),端口号为2049;2、简单网络管理协义(SNMP),端口号为161;3、域名系统(DNS),端口号为53;4、简单文件传输系统(TFTP),端口号为69;5、动态主机配置协议(DHCP),端口号为68;6、路由信息协议,端口号为520等。

如何使用PHP和UDP协议实现异步通信在现代的互联网应用中,异步通信已成为了一种非常重要的方式。通过使用异步通信,可以在不阻塞主线程的情况下,实现并发处理用户请求,提高系统的性能和响应速度。而PHP作为一种流行的后端编程语言,如何使用UDP协议实现异步通信呢?本文将介绍如何在PHP中使用UDP协议实现简单的异步通信,并附上具体的代码示例。一、UDP协议简介U

tcp/ip全称是“Transmission Control Protocol/Internet Protocol”,中文意思为“传输控制协议/网际协议”。TCP/IP协议不仅仅指的是TCP和IP两个协议,而是指一个由FTP、SMTP、TCP、UDP、IP等协议构成的协议簇,只是因为在TCP/IP协议中TCP协议和IP协议最具代表性,所以被称为TCP/IP协议。

win32和win64的区别是:1、win32是指Microsoft Windows操作系统的32位环境,win64是指Microsoft Windows操作系统的64位版本,比32位版本更加稳定快速;2、win32最高支持2G的内存,win64必须是4G以上内存;3、win64支持基于64位的处理器,而win32却不能完全支持;4、win32追求简洁,win64追求性能。

Vue3和Vue2的区别:更丰富的生命周期钩子Vue是一种流行的JavaScript框架,用于构建交互式的Web应用程序。Vue2是Vue.js的稳定版本,而Vue3是Vue.js的最新版本。Vue3带来了许多改进,其中之一是更丰富的生命周期钩子。本文将介绍Vue3和Vue2生命周期钩子的区别,并通过代码示例进行演示。Vue2的生命周期钩子在Vue2中,我们

win7有好几个版本,对于这些琳琅满目的win7版本,很多朋友也是不知道这些win7版本有什么区别了,功能上哪个更好,哪个系统更适合自己,这里小编和大家介绍下win7企业版与win7旗舰版有什么区别的详细介绍,大家快来看看吧。1、Windows7企业版(Enterprise)这个版本面向企业市场的高级版本,主要对象是企业用户以及其市场,满足企业数据共享、管理、安全等需求。包含多语言包、UNIX应用支持、BitLocker驱动器加密、分支缓存(BranchCache)等。通过大量授权给有与微软签订

如何利用PHP与TCP/IP协议进行数据通信引言:在现代互联网时代,数据通信是非常重要的一个方面。无论是客户端与服务器之间的通信,还是不同服务器之间的通信,TCP/IP协议一直是最常用的通信协议之一。本文将介绍如何利用PHP语言与TCP/IP协议进行数据通信,并提供相关的代码示例。一、TCP/IP协议简介TCP/IP协议是Internet协议簇的基础,它定义

UDP(用户数据报协议)是一种轻量级的无连接网络协议,常用于时间敏感的应用程序。它允许应用程序在无需建立TCP连接的情况下发送和接收数据。示例Java代码可用于创建UDP服务器和客户端,服务器监听传入数据报并响应,客户端发送消息并接收响应。该代码可用于构建聊天应用程序或数据收集系统等实战案例。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
