当前位置:网站首页>Some thoughts on port forwarding program
Some thoughts on port forwarding program
2022-06-29 06:49:00 【inspire121】
If I want to write a port forwarding program , Similar to the multi person chat room , Under a LAN ,
Everyone sends a message to the server , Then the server will forward this message to the corresponding person .
therefore socket Communication is no longer between individuals , It's communication between people .
There is no need to reopen one every time socket, But the use of socket I / O stream .
So how should it be written ?
First , An independent network is set for each communication device under the LAN IP,
then , Maintain a dynamic array on the server side , The array contains the data that has been connected to the server socket object ,
Accurately speaking , In this way socket object 、 Each represents a client .
Each one is established with the server side socket Communication client , Both threads are open , One is responsible for outputting the character stream ,
One is responsible for receiving the character stream .
In the server-side dynamic array , You need to keep looking through the loop IP、 Forward messages , How to do it? ?
In the information sent by the client , Containing the target object IP And information ,
After receiving the information on the server , Let each element in the maintained dynamic array (socket object ) Go to
Query the information sent IP Is it the same as your own , If they are the same, the character stream is output .
This is actually an abstraction , On the server side socket The shadow of communication , Forward messages through such shadows ,
Disadvantages: high consumption of hardware resources , Every time a client joins the group chat , Then the server side needs to add a socket shadow ,
At the same time the socket The shadow also needs to traverse other socket shadow . This is actually very resource consuming , Multiplicative relation .
For example, communication between two people is 2 * 2, So ten person correspondence is 10 * 10.
Such a network structure is actually understandable .
What if it is between two network segments ?
For example, my device is wired at the same time 边栏推荐
- Difference between static and final
- WDCP访问不存在的路径全部跳转到首页不返回404的解决办法
- Analysis comp122 the Caesar cipher
- Service grid ASM year end summary: how do end users use the service grid?
- Overlay histogram with density curve
- SCM engineering experience - time slice
- Difference between URI and URL
- jetson tx2
- JDBC | Chapter 5: closing and releasing JDBC connection resources
- Case of single file component files
猜你喜欢

Rich material libraries make modeling easy and efficient for developers

Linux Installation redis

分享 10 个 JS Promise 相关的面试题

Agile invincible event

Annual inventory review of Alibaba cloud's observable practices in 2021

Fresnel diffraction with rectangular aperture based on MATLAB

Yyds dry goods inventory meituan's two-sided experience, and finally there was a surprise?

Browser local storage

RPC和RMI

Failure: unable to log in to "taxpayer equity platform"
随机推荐
Yyds dry goods inventory meituan's two-sided experience, and finally there was a surprise?
Configuring the flutter development environment
Baidu applet automatically submits search
Activiti Designer
How to combine two byte arrays [repeat] - how to combine two byte arrays [duplicate]
Can redis implement hot standby?
Chapter V online logic analyzer signaltap
[deep learning] - maze task learning I (to realize the random movement of agents)
Rich material libraries make modeling easy and efficient for developers
Why should enterprises do more application activities?
Li Kou daily question - day 30 -594 Longest harmonic subsequence
QT (x): packaging and deployment
Fresnel diffraction with rectangular aperture based on MATLAB
SCM engineering experience - time slice
Hyperledger Fabric 2. X custom smart contract
Ribbon service invocation and load balancing
Design of leetcode simple problem goal parser
WDCP访问不存在的路径全部跳转到首页不返回404的解决办法
配置Flutter开发环境
Small program large screen adaptation Guide