简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM