当前位置:网站首页>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 边栏推荐
- Unity ar shadow shadow
- Antd work item memo w3.0
- QT (x): innosetup for software packaging
- 力扣每日一题-第30天-1523.位1的个数
- What is the "danksharding" of V God Kop on Valentine's day?
- Subtotal of C language -- basic data types and their representations
- Service grid ASM year end summary: how do end users use the service grid?
- Difference between static and final
- It is the only one in China that Alibaba cloud container service has entered the Forrester leader quadrant
- SCM engineering experience - time slice
猜你喜欢

Leetcode simple problem building arrays with stack operation

Maximum ascending subarray sum of leetcode simple problem

RPC和RMI

Service grid ASM year end summary: how do end users use the service grid?

Test Development - ten years of sharpening one sword (VII) interface test tool postman

json tobean

Games101 Lecture 10 geometry 1 Notes

Baidu applet automatically submits search

Design and practice of kubernetes cluster and application monitoring scheme
![[deep learning] - maze task learning I (to realize the random movement of agents)](/img/c1/95b476ec62436a35d418754e4b11dc.jpg)
[deep learning] - maze task learning I (to realize the random movement of agents)
随机推荐
try anbox (by quqi99)
层次分析法
Maximum ascending subarray sum of leetcode simple problem
Hyperledger Fabric 2. X custom smart contract
Browser local storage
SCM engineering experience - time slice
Difference between static and final
Antd work item memo w3.0
Draw smooth curves - methods needed - drawing smooth curves - methods needed
AIRNET notes 1
Rearrangement string of leetcode simple question
Go basic data types: characters and strings
JDBC | Chapter 5: closing and releasing JDBC connection resources
C language pointer to function
Design and practice of kubernetes cluster and application monitoring scheme
Are there too many programmers in China at present?
Overlay histogram with density curve
VerilogA——动态比较器
Go compile source code (window environment)
[C language] flexible array