title: What is "backlog" in TCP connections?
body: <p>Below, you see a python program that acts as a server listening for connection requests to port <em>9999</em>:</p>
  
  <pre><code># server.py 
  import socket                                         
  import time
  
  # create a socket object
  serversocket = socket.socket(
              socket.AF_INET, socket.SOCK_STREAM) 
  
  # get local machine name
  host = socket.gethostname()                           
  
  port = 9999                                           
  
  # bind to the port
  serversocket.bind((host, port))                                  
  
  # queue up to 5 requests
  serversocket.listen(5)                                           
  
  while True:
      # establish a connection
      clientsocket,addr = serversocket.accept()      
  
      print("Got a connection from %s" % str(addr))
      currentTime = time.ctime(time.time()) + "\r\n"
      clientsocket.send(currentTime.encode('ascii'))
      clientsocket.close()
  </code></pre>
  
  <p>The questions is what is the function of the parameter of <code>socket.listen()</code> method (i.e. <code>5</code>).</p>
  
  <p>Based on the tutorials around the internet:</p>
  
  <blockquote>
    <p>The backlog argument specifies the maximum number of queued
    connections and should be at least 0; the maximum value is
    system-dependent (usually 5), the minimum value is forced to 0.</p>
  </blockquote>
  
  <p>But:</p>
  
  <ol>
  <li>What are these <em>queued connections</em>? </li>
  <li>Does it make any difference for client requests? (I mean is the server that is running with <code>socket.listen(5)</code> different from the server that is running with <code>socket.listen(1)</code> in accepting connection requests or in receiving data?)</li>
  <li>Why is the minimum value zero? Shouldn't it be at least <code>1</code>?</li>
  <li>Is there a preferred value?</li>
  <li>Is this <code>backlog</code> defined for TCP connections only or does it apply for UDP and other protocols too?</li>
  </ol>