You might find this useful
Simple threaded chat server. You could easily add code to check the scalar value of the array holding the active sockets, and refuse connections if over a certain value. But you can also set that limit in the IO::Socket::INET listen option..... so I can't
fully understand your question.
You can share them with other applications thru the filenos of the filehandles and pid
of the server script. Look in /proc/$pid/fd for a list of your sockets. As long as you have user rights to those processes, you can read/write to them.