Reuse of sockets

ぃ、小莉子 提交于 2019-12-12 06:14:17

问题


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?

来源:https://stackoverflow.com/questions/28234188/reuse-of-sockets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!