当前位置:网站首页>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 边栏推荐
- Meta metauniverse female safety problems occur frequently. How to solve the relevant problems in the metauniverse?
- Pytest (7) -yield and termination function
- 想请教一下,究竟有哪些劵商推荐?在线开户是安全么?
- What is 'EC2-Other' filter in 'Cost Explorer' dashboard mean? [closed]
- Antlr4 recognizes the format of escape string containing quotation marks
- Easy to understand TCP four waves (multi picture explanation)
- Observer mode vs publish subscribe mode
- Rich material libraries make modeling easy and efficient for developers
- The simple problem of leetcode is to divide an array into three parts equal to sum
- 关于 localStorage 的一些高阶用法
猜你喜欢

The annual technology inventory of cloud primitives was released, and it was the right time to ride the wind and waves

Sourcetree remote red exclamation point

JDBC连接数据库,socket发送客户端。

Single application and microservice application

Maximum ascending subarray sum of leetcode simple problem

Installing modules in pycharm

作为一名合格的网工,你必须掌握的 DHCP Snooping 知识!

Difference between URI and URL

Fault: ntfrs warning log for id13562

Failure: unable to log in to "taxpayer equity platform"
随机推荐
关于端口转发程序的一点思考
Fault: NetBt log for id4321
Unity ar shadow shadow
Principle of screen printing adjustment of EDA (cadence and AD) software
QT (x): control operation
2022.02.15
Presto-Trial
flutter配置国内镜像,连接真机
Yyds dry goods inventory meituan's two-sided experience, and finally there was a surprise?
Part 63 - interpreter and compiler adaptation (II)
The generation of leetcode simple questions each character is an odd number of strings
JDBC连接数据库,socket发送客户端。
What are the uses of static?
Unity AR Shadow 阴影
Teach you how to develop your own NPM package (publish to the NPM official website)
Test Development - ten years of sharpening one sword (VII) interface test tool postman
Ribbon service invocation and load balancing
Json对象和Json字符串的区别
The annual technology inventory of cloud primitives was released, and it was the right time to ride the wind and waves
Maximum ascending subarray sum of leetcode simple problem