def handle_json(self, data): data = json.loads(data) response = self.answer(data) inspector_logger.debug(f"response index ---- {response}") # send back to server bytes_data = json.dumps(response).encode("utf-8") protocol.send_json(self.socket, bytes_data)
def handle_json(self, data): data = json.loads(data) self.select_fantom(data) response = self.smart_answer(data) # send back to server bytes_data = json.dumps(response).encode("utf-8") protocol.send_json(self.socket, bytes_data)
def send_json_to_player(player, data): """ Converts a python object to json and send it to a client. :param player: object of the class Player. Either the fantom or the inspector. :param data: python object sent to the player. """ logger.debug(f"send json to player {player}") msg = json.dumps(data).encode("utf-8") protocol.send_json(clients[player], msg)
def send_answer(self): while 42: with answ_q_lock: print(self.id, " waiting for: ", len(answ_queue), answ_queue[0]['player_id'] if len(answ_queue) else '') if len(answ_queue ) != 0 and answ_queue[0]['player_id'] == self.id: bytes_data = json.dumps( answ_queue[0]['data']).encode("utf-8") answ_queue.pop(0) print('sending') protocol.send_json(self.socket, bytes_data) return time.sleep(1)
def handle_json(self, data): data = json.loads(data) print("DATA : \n") print(data) print("\n") print("\n") if data["data"] == "win": set_win(data["data"]) self.end = True return elif data["data"] == "lose": set_win(data["data"]) self.end = True return #TODO evaluate reward here response = self.answer(data) # send back to server bytes_data = json.dumps(response).encode("utf-8") protocol.send_json(self.socket, bytes_data)
def send_json(self, response): bytes_data = json.dumps(response).encode("utf-8") protocol.send_json(self.socket, bytes_data) return