当前位置:网站首页>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 .
边栏推荐
- 2020-2022两周年创作纪念日
- 养不起真猫,就用代码吸猫 -Unity 粒子实现画猫咪
- 手机开证券账户安全吗?怎么买股票详细步骤
- DenseNet
- "21 days proficient in typescript-3" - install and build a typescript development environment md
- C# TCP如何设置心跳数据包,才显得优雅呢?
- American chips are no longer proud, and Chinese chips have successfully won the first place in emerging fields
- 机器学习编译第2讲:张量程序抽象
- [deep learning] how does deep learning affect operations research?
- [729. My Schedule i]
猜你喜欢
Clear restore the scene 31 years ago, volcanic engine ultra clear repair beyond classic concert
[729. My Schedule i]
普洛斯数据中心发布DC Brain系统,科技赋能智慧化运营管理
浏览器渲染原理以及重排与重绘
【刷題篇】鹅廠文化衫問題
How to uninstall MySQL cleanly
中间表是如何被消灭的?
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
二叉树相关OJ题
Jarvis OJ Flag
随机推荐
Jarvis OJ Telnet Protocol
极坐标扇图使用场景与功能详解
机器学习编译第2讲:张量程序抽象
Deep learning plus
深潜Kotlin协程(二十一):Flow 生命周期函数
Spring Festival Limited "forget trouble in the year of the ox" gift bag waiting for you to pick it up~
网站页面禁止复制内容 JS代码
Jarvis OJ shell traffic analysis
Detailed explanation of use scenarios and functions of polar coordinate sector diagram
Win11 prompt: what if the software cannot be downloaded safely? Win11 cannot download software safely
拷贝方式之DMA
Jarvis OJ Flag
How to uninstall MySQL cleanly
2020-2022 two-year anniversary of creation
解决CMakeList find_package找不到Qt5,找不到ECM
sqlserver 做cdc 要对数据库性能有什么要求么
如何将mysql卸载干净
【剑指 Offer】63. 股票的最大利润
Summary of methods for finding intersection of ordered linked list sets
文件操作--I/O