title: How do I create a TCP server that will accept only one connection at a time?
body: <p>I'm writing a client-server pair in C++ using Linux sockets.  I want the server to listen for a connection, and while one client is connected the server should reject any other clients that try to connect.</p>
  
  <p>I tried implementing this by setting the backlog parameter in the <a href="http://linux.die.net/man/3/listen" rel="noreferrer">listen</a> function to 0 and to 1 and neither one of those values seems to work.  The first client connects as expected, but any subsequent clients just block while the first client finishes.  What's really confusing to me is that they don't block on connecting to the server, they block on the first read.</p>
  
  <p>I used <a href="http://tldp.org/LDP/LG/issue74/tougher.html" rel="noreferrer">the code here</a> to get started writing my client and server.  Does anyone know what I need to change to get the server to accept only one client connection, and drop any subsequent connection attempts?</p>