I'm programming a server code using C language that must accept only few numbers of clients and if extra one arrives the server will put that client to wait until one of the old clients terminated.
For example (The server can accept 10 clients only, if new client arrived the server will put that client to wait until one of the 10 clients terminated, then he can be served).
I know i have to use signal()
function, after listen()
function and before accept()
and create a value that counts the number of clients, but i don't know how to use it correctly.
Can any one give me a hint or simple example.
Thank you,,,,,,
There is no need to use
signal()
. Example:Note: This program binds to a random free port, which you can find out with e. g.
netstat -tlp
. Of course you can alsobind()
to a specific address and port. In any case you can test it with e. g.nc hostname port
.