当前位置:网站首页>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 .
边栏推荐
- 接口和抽象类/方法学习 demo
- Sub database and sub table
- Why is count (*) slow
- 再一个技巧,每月稳赚3万+
- 一、MySQL基础
- Solution: how to use bash batch command in win10
- 2019 top tennis cup upload
- Network protocol details: IP
- How to import PS style? Photoshop style import tutorial
- Be diligent in talking about what sidelines you can do now
猜你喜欢

Idea 如何新建一个groovy的项目(图文详细解释)

如何将Photoshop图层复制到其他文档

日落红暖色调调色滤镜luts预设Sunset LUTs 1

Installation and template setting of integrated development environment pychar

kali系统arp介绍(断网嗅探密码抓包)

How to create an applet project

一道数学题,让芯片巨头亏了5亿美金

TypeScript 详解

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

精选用户故事|洞态在聚水潭的误报率几乎为0,如何做到?
随机推荐
Hiding skills of Photoshop clipping tool
Complete Binary Tree
STM32_ HAL_ SUMMARY_ NOTE
How to copy Photoshop layers to other documents
「Photoshop2021入门教程」对齐与分布制作波点图案
Tcp server是如何一个端口处理多个客户端连接的(一对一还是一对多)
feign调用丢失请求头问题解决及原理分析
Final Cut Pro Chinese tutorial (1) basic understanding of Final Cut Pro
文件对话框
写代码涉及到的斜杠/和反斜杠\
Plato Farm有望通过Elephant Swap,进一步向外拓展生态
Explanation of index failure principle and its common situations
探寻通用奥特能平台安全、智能、性能的奥秘!
ps样式如何导入?Photoshop样式导入教程
Hiding skills of Photoshop clipping tool
JS tips
What about PS too laggy? A few steps to help you solve the problem
Plane conversion (displacement, rotation, scaling)
事件(event)
树莓派rtmp推流本地摄像头图像