victor wrote:
I want my code to accept only connections to the max of N.. if any
client tries to connect to my code when already there are N
connections, then it musst be refused... How do i do it?
P.S::: I can accept the connection then close the socket.. But is
there any other elegant way?
After you call listen(), the socket enter the LISTEN state. When client
connect, it send SYN, which enter a incomplete connection queue on
server. Server replies with SYN+ACK, and socket enter the SYN_RCVD state.
Unless client try a SYN flood attack, it will reply with ACK. When the
ACK is received at server, the socket enter the ESTABLISHED state and is
moved from the incomplete queue to the complete queue.
Now, if accept() is called by the server, you remove it from the
completed queue.
Why would need another way to remove a connection from the completed queue?
If you don't remove it, you will sooner or later trigger a SYN flood on
your own! :)
--
Tor