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.
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()
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?
Edit: This is Python 2.6.4
Edit 2: http://www.youtube.com/watch?v=rVOG3JdbHAM&feature=youtu.be 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?