Number of socket clients connected to server

核能气质少年 提交于 2020-01-24 17:23:31

问题


I have a NIO TCP server which accepts and reads data from clients. I would like to know the count number of clients connected at regular intervals, for monitoring purpose (like netstat or lsof) in java. Is there any way to achieve this without maintaining a counter and increment it every time a client connects?

Something like:

int clientsConnected = serverSocket.getClientsConnected();

回答1:


There is no way that I can think of, you would just have to have a variable called count and increment it each and every time.

int count = 0;
server.accept(); 
count++;


来源:https://stackoverflow.com/questions/23191185/number-of-socket-clients-connected-to-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!