0

I have a simple TCP server using the socketserver library. It used to work fine, but now I get this error message whenever I run it:

socket.error: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted

Here is the code:

class Handler(socketserver.StreamRequestHandler):
    def handle(self):
        sys.stdout = self.wfile
        self.data = str(self.request.recv(1024).strip(), "utf-8")
        exec(self.data, globals())

    def handle_error(request, client_address):
        print("Quitting...")

if __name__ == "__main__":
    HOST, PORT = "localhost", 5555

    server = socketserver.TCPServer((HOST, PORT), Handler)

    server.serve_forever()

I've tried changing the port, but I get the same error. What is the problem?

rlms
  • 10,650
  • 8
  • 44
  • 61
  • This other SO question (http://stackoverflow.com/questions/4526933/python-urllib2-urlerror-urlopen-error-errno-10048-only-one-usage-of-each-so) is not necessarily an exact duplicate (since I think the asker of that question was not using `socketserver`), but there may be significant overlap with your issue. Perhaps previous connections using the ports you have tried have not cleanly closed, and therefore they are in a `TIME_WAIT` status. – rchang Jan 30 '15 at 11:52
  • @rchang That is the usual problem with this error, but I've changed the port enough (and to high values) that it seems unlikely that all those ports are being used. – rlms Jan 30 '15 at 11:54

0 Answers0