title: Issue with simple python server. socket.accept() accepts input /favicon.ico even after I (supposedly) close the socket
body: <p>I'm new to stack overflow and socket programming. Thanks in advance for your help!</p>
  
  <p>A little background: I am trying to implement a simple python server. I am trying to connect through TCP and am just trying to return the some parsed text from the request (I am trying to send back the text variable "message").</p>
  
  <p>However, it seems that even after I close the connection, the server side socket accepts some random input called "/favicon.ico" and I am not sure where this is coming from. This loop accepts "/favicon.ico" a few times before returning to the state where it is waiting for a connection.</p>
  
  <p>Does anyone know what is going on? 
  <strong>Here is my code:</strong></p>
  
  <pre><code>#import socket module
  from socket import *
  serverSocket = socket(AF_INET, SOCK_STREAM)
  #Prepare a sever socket
  serverPort = 10016
  serverName = '192.168.56.101'
  serverSocket.bind((serverName,serverPort))
  serverSocket.listen(0)
  
  while True:
      #Establish the connection
      print 'Ready to serve...'
      connectionSocket, addr = serverSocket.accept()
  
      message = connectionSocket.recv(4096)
      filename = message.split()[1]
      #f = open(filename[1:])
      print filename
      connectionSocket.send(message)
      connectionSocket.close()
  
      print '\nYou got to this line\n'
  </code></pre>
  
  <p><strong>-------------------------------------------------------------</strong></p>
  
  <p><strong>Here is my client-side request:</strong> <a href="http://192.xxx.56.101:10016/sophie.JPG" rel="nofollow">http://192.xxx.56.101:10016/sophie.JPG</a> (stack overflow made me x out the IP)</p>
  
  <p><strong>And my client-side output, which seems to be returned alright</strong>: </p>
  
  <pre><code>GET /sophie.JPG HTTP/1.1
  Host: 192.168.56.101:10016
  User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Language: en-US,en;q=0.5
  Accept-Encoding: gzip, deflate
  Connection: keep-alive
  </code></pre>
  
  <p><strong>-------------------------------------------------------------</strong></p>
  
  <p><strong>And here is my server-side output (print statements):</strong></p>
  
  <pre><code>name@name-VirtualBox:~/Documents/python_scripts$ python server2.py
  Ready to serve...
  /sophie.JPG
  You got to this line
  Ready to serve...
  /favicon.ico
  You got to this line
  Ready to serve...
  /favicon.ico
  You got to this line
  Ready to serve...
  /favicon.ico
  You got to this line
  Ready to serve...
  </code></pre>
  
  <p><strong>----------------------------------------------------------------------</strong></p>
  
  <p><strong>I would have expected the output to simply be the first four lines:</strong></p>
  
  <pre><code>Ready to serve...
  /sophie.JPG
  You got to this line
  Ready to serve...
  </code></pre>
  
  <p><strong>-------</strong></p>
  
  <p>I expected only these four lines back since the server should return to its <em>waiting</em> state after the connection is closed. However, it is still accepting some input called <strong>/favicon.ico</strong> and running through the loop a few more times before it goes back to the waiting state.</p>
  
  <p>Does anyone have an idea as to what is going on here?</p>
  
  <p>Thanks!</p>
  
  <p><strong>----------------------------------------</strong></p>
  
  <p><strong>Update:</strong></p>
  
  <p>Ok, so I added the line you suggested, and I see that the browser is sending these extra requests and that they are (according to you) getting queued.</p>
  
  <p>In addition to that, I also changed the line:</p>
  
  <pre><code>serverSocket.listen(0)
  </code></pre>
  
  <p>to</p>
  
  <pre><code>serverSocket.listen(1)
  </code></pre>
  
  <p>and then my code runs as I would want it to. (Actually, I have tried it again now, and it does not run as expected. the <em>/favicon.ico</em> request is still being sent)</p>
  
  <p>I guess I have a couple followup questions about what is happening:</p>
  
  <ol>
  <li><p>Why is the browser making more requests for <em>/favicon.ico</em> when I have not asked it to (with the original code serverSocket(0)?</p></li>
  <li><p>Now that I have allowed the server to listen to more than one socket connection, why do the bogus connection requests (<em>/favicon.ico</em>) disappear?</p></li>
  </ol>
  
  <p>And thanks, I will read up on syn cookies as well.</p>