当前位置:网站首页>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 .
边栏推荐
- "Photoshop2021 introductory tutorial" flatten "perspective images
- SVN使用详解
- 传智教育|软件测试工程师未来的发展方向有哪些?
- 多态的详讲
- On the problem that Gorm's beforedelete hook method does not work
- 不需手动安装cuda和cudnn,通过一行程序即可安装tensorflow-gpu,以tensorflow-gpu2.0.0,cuda10.0,cudnn7.6.5为例
- The execution process of a select statement in MySQL
- 树莓派rtmp推流本地摄像头图像
- Plato farm is expected to further expand its ecosystem through elephant swap
- 【搜索】双向广搜 + A*
猜你喜欢

ps太卡怎么办?几步帮您解决问题

C语言 通讯录管理系统(链表,手机号码分段存储,txt文件存取,完整源码)

树莓派输出PWM波驱动舵机

Svn usage details
![[C language] dynamic memory management](/img/20/3970cd2112204774a37b5a1d3bdce0.png)
[C language] dynamic memory management
![[search] connectivity model of DFS + search order](/img/67/40444e53621371b1c8b47f22ebc956.png)
[search] connectivity model of DFS + search order

js小技巧

Plato farm is expected to further expand its ecosystem through elephant swap

CDH cluster integration external Flink (improved version - keep pace with the times)

Idea 如何新建一个groovy的项目(图文详细解释)
随机推荐
Knowledge about hash index and b+ tree
Final Cut Pro中文教程 (1) 基础认识Final Cut Pro
Easily download data in power Bi reports with power auto
[error reporting]: cannot read properties of undefined (reading 'prototype')
二维数组求和 练习
节流函数的demo——正则表达式匹配
Why is select not recommended*
项目对接支付宝支付,内网穿透实现监听支付宝的支付成功异步回调通知
vim的基本操作
Slashes / and backslashes involved in writing code\
事件的接受与忽略
Photoshop裁剪工具隐藏技巧
Svn usage details
On the problem that Gorm's beforedelete hook method does not work
How does PS import LUT presets? Photoshop import LUT color preset tutorial
"Photoshop2021 tutorial" align and distribute to make dot patterns
接口和抽象类/方法学习 demo
树莓派rtmp推流本地摄像头图像
js小技巧
Standard dialog qmessagebox