def handle_request(self, conn, addr): """ Handler request """ while not self.__shutdown: conn.settimeout(5) try: message = parse_message(conn.recv) if not message: break command, data = message except socket.timeout: break if command == 'connect': conn.sendall(make_message('connected', 'HELLO')) elif command == 'ping': conn.sendall(make_message('pong')) elif command == 'pingd': conn.sendall(make_message('pongd', data)) elif command == 'quit': conn.sendall(make_message('ackquit', data)) break elif command == 'finish': conn.sendall(make_message('ackfinish', data)) self.__shutdown = True break if self.__shutdown: conn.sendall(make_message('ackfinish')) conn.close()
def send(self, command, message=''): self.socket.sendall(make_message(command, message))