Sameera.San
Sameera.San

Reputation: 77

Number of Connections in Java Socket

Simply I have a java server program and I want to count number of clients connected the socket, increment on new connection and decrement when connections are closed. What is the best way to achieve this ?

Thanks!

Upvotes: 0

Views: 1098

Answers (1)

Aakash Verma
Aakash Verma

Reputation: 3994

I am not sure about the code logic so you'd have to see the decrement part. And even this is a workaround I believe.

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

And decrement it every time you close the socket.

Upvotes: 2

Related Questions