当前位置:网站首页>C how TCP restricts the access traffic of a single client
C how TCP restricts the access traffic of a single client
2022-07-05 16:55:00 【Ruo Qiming】
List of articles
One 、 explain
Use RRQMSocket After creating the server , Want to realize a current limiting function , How should it be realized ?
Two 、 Assembly source code
2.1 Source location
2.2 documentation
The front page of the document
3、 ... and 、 install
Nuget install RRQMSocket
that will do , See link blog for specific steps .
VS、Unity Installation and use Nuget package
Four 、 Creating plug-ins
public class MyThrottlingPlugin : TcpPluginBase
{
private readonly int m_max;
[DependencyInject(10)]
public MyThrottlingPlugin(int max)
{
this.m_max = max;
this.Order = int.MaxValue;// Raise priority
}
protected override void OnConnected(ITcpClientBase client, RRQMEventArgs e)
{
client.InitFlowGate(this.m_max);// Initialize the flow counter .
base.OnConnected(client, e);
}
protected override void OnReceivedData(ITcpClientBase client, ReceivedDataEventArgs e)
{
client.GetFlowGate().AddCheckWait(e.ByteBlock.Len);// It is assumed here that ByteBlock data . If it is a custom adapter , Increment as needed .
base.OnReceivedData(client, e);
}
}
5、 ... and 、 Create an extension class
/// <summary>
/// A flow counter extension .
/// </summary>
static class DependencyExtensions
{
public static readonly DependencyProperty FlowGateProperty =
DependencyProperty.Register("FlowGate", typeof(FlowGate), typeof(DependencyExtensions), null);
public static void InitFlowGate(this IRRQMDependencyObject dependencyObject, int max)
{
dependencyObject.SetValue(FlowGateProperty, new FlowGate() {
Maximum = max });
}
public static FlowGate GetFlowGate(this IRRQMDependencyObject dependencyObject)
{
return dependencyObject.GetValue<FlowGate>(FlowGateProperty);
}
}
6、 ... and 、 Start the server
static void Main(string[] args)
{
TcpService service = new TcpService();
service.Connecting += (client, e) => {
};// A client is connecting
service.Connected += (client, e) => {
};// There is a client connection
service.Disconnected += (client, e) => {
};// A client is disconnected
service.Received += (client, byteBlock, requestInfo) =>
{
// Receive message from client
string mes = Encoding.UTF8.GetString(byteBlock.Buffer, 0, byteBlock.Len);
Console.WriteLine($" From {
client.ID} Received information :{
mes}");
client.Send(mes);// Return the received information directly to the sender
};
service.Setup(new RRQMConfig()// Load configuration
.UsePlugin()
.SetListenIPHosts(new IPHost[] {
new IPHost("127.0.0.1:7789"), new IPHost(7790) })// Listen to two addresses at the same time
.SetMaxCount(10000)
.SetThreadCount(100))
.Start();// start-up
service.AddPlugin<MyThrottlingPlugin>();
Console.ReadLine();
}
7、 ... and 、 effect
this paper Example demo
actually , The plug-in can also be used for client . meanwhile , It can also limit send out Flow limit .
边栏推荐
- Apple has abandoned navigationview and used navigationstack and navigationsplitview to implement swiftui navigation
- 帮忙看看是什么问题可以吗?[ERROR] Could not execute SQL stateme
- 如何将mysql卸载干净
- Can you help me see what the problem is? [ERROR] Could not execute SQL stateme
- File operation --i/o
- PHP人才招聘系统开发 源代码 招聘网站源码二次开发
- Games101 notes (II)
- StarkWare:欲构建ZK“宇宙”
- C# TCP如何限制单个客户端的访问流量
- PHP strict mode
猜你喜欢
随机推荐
搜索 正排索引 和 倒排索引 区别
Jarvis OJ 远程登录协议
机器学习编译第2讲:张量程序抽象
Data verification before and after JSON to map -- custom UDF
How does win11 change icons for applications? Win11 method of changing icons for applications
JSON转MAP前后数据校验 -- 自定义UDF
Jarvis OJ Flag
Facing new challenges and becoming a better self -- attacking technology er
浏览器渲染原理以及重排与重绘
Jarvis OJ Telnet Protocol
How to set the WiFi password of the router on the computer
Bs-xx-042 implementation of personnel management system based on SSM
时间戳strtotime前一天或后一天的日期
Apple 已弃用 NavigationView,使用 NavigationStack 和 NavigationSplitView 实现 SwiftUI 导航
[es6] add if judgment or ternary operator judgment in the template string
手机开证券账户安全吗?怎么买股票详细步骤
If you can't afford a real cat, you can use code to suck cats -unity particles to draw cats
Do sqlserver have any requirements for database performance when doing CDC
调查显示传统数据安全工具面对勒索软件攻击的失败率高达 60%
[js] 技巧 简化if 判空