def send_and_receive(self): in_buffer = self.rfile out_buffer = self.wfile command = CommandProcessor.receive_command(in_buffer) #print("process cmd: ", command.cmd) if command is not None: reply = CommandStruct(cmd=ServerCommand.Com_ReplyOK) if command.cmd == ServerCommand.Com_Start: #print("start conversation:") pass elif command.cmd == ServerCommand.Com_Stop: #print("end conversation:") return else: server_handle_result = self.handle_request(command) if isinstance(server_handle_result, Serializable): reply.data = server_handle_result elif isinstance(server_handle_result, bool) and server_handle_result: pass else: reply.cmd = ServerCommand.Com_ReplyError reply.data = "command is not valid, please try again" CommandProcessor.send_command(out_buffer, reply) self.send_and_receive()