Вопрос

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();
Это было полезно?

Решение

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++;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top