Question

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();
Was it helpful?

Solution

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++;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top