Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0版本,如何设置Ip黑名单 #766

Open
loveyeguo opened this issue Dec 11, 2024 · 7 comments
Open

2.0版本,如何设置Ip黑名单 #766

loveyeguo opened this issue Dec 11, 2024 · 7 comments

Comments

@loveyeguo
Copy link

1.6版本看到有示例,2.0版本没有找到

@loveyeguo
Copy link
Author

我想实现的效果是,针对特定ip,限制他每分钟的连接次数。因为现在有一些tcp客户端频繁的连接然后断开,导致资源耗尽。

@kerryjiang
Copy link
Owner

@loveyeguo
Copy link
Author

Do it in your middleware:

https://github.com/kerryjiang/SuperSocket/blob/master/src/SuperSocket.Server.Abstractions/Middleware/MiddlewareBase.cs

大佬,有点没看懂啊,屏蔽ip是写在哪个方法里面?

@loveyeguo
Copy link
Author

能给一个简单的示例么?

@loveyeguo
Copy link
Author

现在遇到一个棘手的问题,我使用supersocket编写的tcp服务端,在大量客户端重连,然后间隔0-1秒后又断开的情况,导致方法:

 private async Task KeepAccept(Socket listenSocket)
 {
     while (!_cancellationTokenSource.IsCancellationRequested)
     {
         try
         {
             var client = await listenSocket.AcceptAsync().ConfigureAwait(false);
             OnNewClientAccept(client);
         }
         catch (Exception e)
         {
             if (e is ObjectDisposedException || e is NullReferenceException)
                 break;
             
             if (e is SocketException se)
             {
                 var errorCode = se.ErrorCode;

                 //The listen socket was closed
                 if (errorCode == 125 || errorCode == 89 || errorCode == 995 || errorCode == 10004 || errorCode == 10038)
                 {
                     break;
                 }
             }
             
             _logger.LogError(e, $"Listener[{this.ToString()}] failed to do AcceptAsync");
             continue;
         }
     }

     _stopTaskCompletionSource.TrySetResult(true);
 }

这句代码报错: var client = await listenSocket.AcceptAsync().ConfigureAwait(false);
报错内容: failed to do AcceptAsync远程主机强迫关闭了一个现有的连接。
导致结果: 程序运行几个小时后,后续所有的tcp客户端无法再连接。
如何解决?

@chucklu
Copy link
Contributor

chucklu commented Dec 12, 2024

Do it in your middleware:
https://github.com/kerryjiang/SuperSocket/blob/master/src/SuperSocket.Server.Abstractions/Middleware/MiddlewareBase.cs

大佬,有点没看懂啊,屏蔽ip是写在哪个方法里面?

public virtual ValueTask RegisterSession(IAppSession session)

@loveyeguo
Copy link
Author

Do it in your middleware:
https://github.com/kerryjiang/SuperSocket/blob/master/src/SuperSocket.Server.Abstractions/Middleware/MiddlewareBase.cs

大佬,有点没看懂啊,屏蔽ip是写在哪个方法里面?

public virtual ValueTask RegisterSession(IAppSession session)

这句代码报错: var client = await listenSocket.AcceptAsync().ConfigureAwait(false);
报错内容: failed to do AcceptAsync远程主机强迫关闭了一个现有的连接。
导致结果: 程序运行几个小时后,后续所有的tcp客户端无法再连接。
如何解决?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants