2

I'm trying to create a simple server. This server should be able to handle requests from multiple clients. The problem is, that after second request by one client, it raises: socket.error: [Errno 10053] An established connection was aborted by the software in your host machine

class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
    daemon_threads = True


class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
    def handle(self):

        data = self.request.recv(1024)
        output = data
        response = "{}".format(output)
        self.request.sendall(response)


if __name__ == "__main__":
    HOST, PORT = _host, int(_port)
    server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
    ip, port = server.server_address

    print "Running on: %s:%s" % (HOST, PORT)
    server.serve_forever()

CONSOLE:

CLIENT1->SERVER > anything
SERVER->CLIENT1 > anything
CLIENT1->SERVER > anything
socket.error: [Errno 10053] An established connection was aborted by the software in your host machine

EDIT:

In case it helps:

client.py

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:
    sock.connect((HOST, PORT))

    while True:
        data = raw_input()
        sock.sendall(data + "\n")
        received = sock.recv(1024)
        print "{}".format(received)
finally:
    sock.close()
Milano
  • 18,048
  • 37
  • 153
  • 353
  • 1
    If `handle` method behaves like described here http://stackoverflow.com/a/8628089/5781248, the connection is closed when `handle` method returns i.e. after one request. – J.J. Hakala Jan 28 '16 at 23:33
  • Take a look here: http://www.binarytides.com/code-chat-application-server-client-sockets-python/ might find some useful tidbits – tadamhicks Jan 28 '16 at 23:51

0 Answers0