问题
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