当前位置:网站首页>How does the TCP server handle multiple client connections on one port (one-to-one or one to many)
How does the TCP server handle multiple client connections on one port (one-to-one or one to many)
2022-07-27 05:06:00 【Brother Jane on the road】
We often see that ,TCP It's a one-to-one two-point service ,UDP Support one-to-one 、 One to many 、 Many to many interactive communication . But use Tcp Tool communication , One Tcp The server can connect multiple Tcp client . So is there a conflict between one-to-one and one to many here ?
Not at all . One on one means Tcp Connect , What is? Tcp Connect , Paste directly here Kobayashi great God The explanation of .
The combination of these control information can be called connection . So one-to-one means that a combination of control information can only target one Tcp client .
that Tcp Tools How to realize one to many communication ?

I used tools here to build a TCP Server side (5679) And two TCP client (6159 and 6259).
I see someone on the Internet explaining this problem is , be supposed to tcp When the server handles multiple connections , A new port is created internally to handle . wrong !!! Let's take a look at windows On tcp Socket information is known 
Socket here refers to the socket of communication object IP Address 、 Port number 、 Information such as the progress status of communication operation . A line in the figure is equivalent to a socket . Why do you need the socket concept , When it comes to one to many implementation .
You can see tcp The port of the server has always been 5679, No other ports are displayed , therefore tcp The server has only one port !!!
that tcp How does the server handle multi-user connections ?
Say first conclusion , Server side Socket The program handles . therefore TCP It's one-on-one ,Socket One to many !
Server side socket The program is divided into two modules , That is, the waiting connection module and the module responsible for communicating with the client . When the server program starts and reads the configuration file to complete the initialization operation , Will run the wait to connect module . This module creates sockets , Then enter the suspended state of waiting for connection . Next , When When the client initiates a connection , This module will resume operation and accept connections , Then start the client communication module , And hand over the socket that completes the connection . Next , The client communication module will use the connected socket to communicate with the client , After the communication is over , This module exits .

After copying a new socket , It turned out that the one in waiting company What will happen to sockets connected to state ? In fact, it will continue to exist in the state of waiting for connection , When called again accept, The client connects the package to Time of arrival , It can perform the accept connection operation again . After accepting the new connection , Just like before , The protocol stack will be used for this socket waiting for connection Make a new copy of the word , Then let the client connect to the new replica socket .
The more detailed principle is shown in the figure below 
It is highly recommended to see 《 How is the network connected 》. Don't say anything else. If you have problems, you can communicate more .
边栏推荐
- 安装Pygame
- vim的基本操作
- 【搜索】—— 多源BFS + 最小步数模型
- When using Photoshop, the prompt "script error -50 general Photoshop error appears“
- kali系统arp介绍(断网嗅探密码抓包)
- Acceptance and neglect of events
- Error: cannot read properties of undefined (reading 'then')
- 2022 T2i text generated image Chinese Journal Paper quick view-1 (ecagan: text generated image method based on channel attention mechanism +cae-gan: text generated image technology based on transforme
- 【Acwing】第61场周赛 题解
- How do I reset Photoshop preferences? PS method of resetting preferences
猜你喜欢

Why is count (*) slow

Photoshop裁剪工具隐藏技巧

Photoshop裁剪工具隐藏技巧

Final Cut Pro Chinese tutorial (2) understanding of material window

Dialog introduction

C language address book management system (linked list, segmented storage of mobile phone numbers, TXT file access, complete source code)

MySQL下载安装 & 完美卸载
![[search] flood fill and shortest path model](/img/22/5240c9ff6ea3c7c1017e3e9a4a27cb.png)
[search] flood fill and shortest path model

【搜索】Flood Fill 和 最短路模型

QT 菜单栏、工具栏和状态栏
随机推荐
Dialog introduction
Reproduce ssa-gan using the nine day deep learning platform
[C language] detailed explanation of user-defined types (structure + enumeration + Union)
STM32_ HAL_ SUMMARY_ NOTE
探寻通用奥特能平台安全、智能、性能的奥秘!
QT 菜单栏、工具栏和状态栏
On the problem that Gorm's beforedelete hook method does not work
Review of various historical versions of Photoshop and system requirements
Another skill is to earn 30000 yuan a month+
事件过滤器
Approval of meeting OA
Photoshop裁剪工具隐藏技巧
Solution: read the files with different names in the two folders and deal with the files with different mappings
STM32 Hal serial port (uart/usart) debugging experience (I) -- basic knowledge of serial port communication +hal library code understanding
再一个技巧,每月稳赚3万+
Deep Qt5 signal slot new syntax
ps怎么导入lut预设?Photoshop导入lut调色预设教程
微淼联合创始人孙延芳:以合规为第一要义,做财商教育“正规军”
"Photoshop2021 tutorial" adjust the picture to different aspect ratio
[C language] dynamic memory management