当前位置:网站首页>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 .
边栏推荐
- DenseNet
- Single merchant v4.4 has the same original intention and strength!
- 深潜Kotlin协程(二十一):Flow 生命周期函数
- C# TCP如何限制单个客户端的访问流量
- Apple has abandoned navigationview and used navigationstack and navigationsplitview to implement swiftui navigation
- Flet教程之 11 Row组件在水平数组中显示其子项的控件 基础入门(教程含源码)
- Deep dive kotlin synergy (XXI): flow life cycle function
- 2020-2022两周年创作纪念日
- OneForAll安装使用
- Summary of PHP pseudo protocol of cisp-pte
猜你喜欢
【729. 我的日程安排表 I】
How to uninstall MySQL cleanly
Jarvis OJ Webshell分析
二叉树相关OJ题
Fleet tutorial 09 basic introduction to navigationrail (tutorial includes source code)
Flet教程之 12 Stack 重叠组建图文混合 基础入门(教程含源码)
调查显示传统数据安全工具面对勒索软件攻击的失败率高达 60%
Accès aux données - intégration du cadre d'entité
Data access - entityframework integration
Flet tutorial 12 stack overlapping to build a basic introduction to graphic and text mixing (tutorial includes source code)
随机推荐
Flet教程之 11 Row组件在水平数组中显示其子项的控件 基础入门(教程含源码)
清晰还原31年前现场,火山引擎超清修复Beyond经典演唱会
Spring Festival Limited "forget trouble in the year of the ox" gift bag waiting for you to pick it up~
[es6] 模板字符串内添加if判断或添加三元运算符判断
PHP talent recruitment system development source code recruitment website source code secondary development
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
Jarvis OJ 简单网管协议
【深度学习】深度学习如何影响运筹学?
C# TCP如何限制单个客户端的访问流量
Jarvis OJ simple network management protocol
树莓派4b安装Pytorch1.11
China Radio and television officially launched 5g services, and China Mobile quickly launched free services to retain users
文件操作--I/O
Games101 notes (III)
Combined use of vant popup+ other components and pit avoidance Guide
Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要
【学术相关】多位博士毕业去了三四流高校,目前惨不忍睹……
Detailed explanation of use scenarios and functions of polar coordinate sector diagram
Apple has abandoned navigationview and used navigationstack and navigationsplitview to implement swiftui navigation
American chips are no longer proud, and Chinese chips have successfully won the first place in emerging fields