I always keep track of the connected client sockets, so that I can disconnect them at will, for example to restart the server in a correct manner. If you keep track of the connected client sockets, you can simple get the size of the list which gives you the number of connected clients.
WM. What about weapons of mass-construction?