Domanda

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();
È stato utile?

Soluzione

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++;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top