当前位置:网站首页>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 边栏推荐
- What are the uses of static?
- What are the uses of wireless pressure collectors?
- Ribbon service invocation and load balancing
- [deep learning] - maze task learning I (to realize the random movement of agents)
- How does schedulerx help users solve distributed task scheduling problems?
- C language pointer to function
- Linux Installation redis
- Redistemplate handles hash integer type problem resolution
- Delete tag
- Single application and microservice application
猜你喜欢

Exclusive download. Alibaba cloud native brings 10+ technical experts to bring new possibilities of cloud native and cloud future

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

package.json的所有配置项及其用法,你都熟悉么

RedisTemplate处理hash整数类型的问题解析

Rearrangement string of leetcode simple question

配置Flutter开发环境

Agile invincible event

Observer mode vs publish subscribe mode

Fault: NetBt log for id4321

力扣今日题-324. 摆动排序 II
随机推荐
National Defense University project summary
【OSPF引入直连路由时巧借静态黑洞路由做汇总】
配置Flutter开发环境
分享 10 个 JS Promise 相关的面试题
力扣每日一题-第30天-1281.整数的各位积和之差
力扣今日题-324. 摆动排序 II
What is 'EC2-Other' filter in 'Cost Explorer' dashboard mean? [closed]
Fresnel diffraction with rectangular aperture based on MATLAB
[c language] [sword finger offer article] - print linked list from end to end
2022.02.15
What are the uses of static?
Ribbon 服务调用与负载均衡
Overlay histogram with density curve
力扣每日一题-第30天-1523.位1的个数
Chapter V online logic analyzer signaltap
Redistemplate handles hash integer type problem resolution
Longest substring between two identical characters of leetcode simple question
JDBC | Chapter 5: closing and releasing JDBC connection resources
WDCP访问不存在的路径全部跳转到首页不返回404的解决办法
JDBC连接数据库,socket发送客户端。