如何使用套接字拒绝c#中的连接尝试 [英] How to reject a connection attempt in c# with sockets

查看:60
本文介绍了如何使用套接字拒绝c#中的连接尝试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发ac#windows表单应用程序,我有一个服务器和多客户端,但客户端数量必须限制,所以如何在这种情况下拒绝连接?

I'm developping a c# windows form app , I have a server and multiclients but the number of clients must be limited so how can I reject a connection in this case ??

推荐答案

在服务器端,每次客户端连接时,都会获得一个新的套接字。跟踪号码连接(使用计数器,列表或其他)。当客户端断开连接然后递减计数器时,从列表中删除等。当你达到所需的阈值
然后通过关闭套接字来删除后续连接尝试。
On the server side, each time a client connects you'll get a new socket. Keep track of the number connects (using a counter, list or whatever). When the client disconnects then decrement the counter, remove from the list, etc. When you get to the threshold you desire then drop subsequent connection attempts by closing the socket.


这篇关于如何使用套接字拒绝c#中的连接尝试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆