title: Can I bind multiple servers to the same TCP port?
body: <p>I would expect having multiple servers on the same port would cause problems. In fact I want it to throw an exception when I try to start two servers on the same port. The problem is, it seems more than happy to start multiple servers on the same port. I can have many instances of the following code running just fine with no exceptions.</p>
  
  <pre><code>import BaseHTTPServer
  import SimpleHTTPServer
  import sys
  
  def main():
      try:
          server = BaseHTTPServer.HTTPServer(('127.0.0.1',5000), SimpleHTTPServer.SimpleHTTPRequestHandler)
          print "On port: " + str(server.socket.getsockname()[1])
      except Exception, e:
          print e
      server.serve_forever()
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>All of which claim to be on port 5000. How can I get it to throw an exception if it tries to use a port that is already taken?</p>
  
  <p>Edit: This is Python 2.6.4</p>
  
  <p>Edit 2: <a href="http://www.youtube.com/watch?v=rVOG3JdbHAM&amp;feature=youtu.be" rel="nofollow">http://www.youtube.com/watch?v=rVOG3JdbHAM&amp;feature=youtu.be</a> Because people seem to think what I am explaining is not possible? Or I am totally misunderstanding people. Either way, this video should clear it up. I start two servers, neither of them print out any exceptions. When I close the first, the second starts working. Why is this happening? I would expect the 2nd server to simply never start and print an exception. Is this not what should happen?</p>