app java服务器-客户端,有多少个客户端连接?
是否可以知道服务器上有多少个客户端连接?有没有一种方法可以做到这一点,也许在网络类中?或者我必须做一个柜台吗?
谢谢
Is it possible to know how many clients there are connected on a server? is there a method that does that, maybe in net class? or must I do a counter?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来
ServerSocket
没有内置返回计数的功能。但由于您必须通过调用accept()
手动接受连接,因此您可以轻松地增加计数器。唯一的困难(如果有的话)是在断开连接时减少计数器。It doesn't look like
ServerSocket
has a built-in of returning a count. But because you have to manually accept connections by callingaccept()
, you can easily increment a counter. The only difficulty (if it is one) is to decrement the counter on disconnect.