def lineReceived(self, line): try: msg = message.parse(line) self.dispatch(msg) except error.Error as e: print "Error handling message: %s" % e msg = message.Message('error', {'message': str(e)}) self.sendLine(str(msg)) self.transport.loseConnection()
def lineReceived(self, line): try: msg = message.parse(line) self.dispatch(msg) except error.Error as e: log.warning("Error handling message: %s", e) msg = message.Message('error', {'message': str(e)}) self.sendLine(str(msg).encode('utf-8')) self.transport.loseConnection()
def drive(self): start = time.time() try: action = self.drive_func(self.world) except Exception: # Make it easy to detect and handle errors by crashing loudly. In # the past we used to print a traceback and continue, and students # had trouble detecting and handling errors. reactor.stop() raise response_time = time.time() - start msg = message.Message('drive', { "action": action, "response_time": response_time }) self.client.send_message(msg)
def client_connected(self): log.info('client connected: joining as %s', self.name) msg = message.Message('join', {"name": self.name}) self.client.send_message(msg)
def add_watcher(self, watcher): self.clients.add(watcher) msg = message.Message("update", self.game.state()) watcher.send_message(str(msg))
def update_clients(self): msg = message.Message('update', self.state()) self.hub.broadcast(msg)
def update_players(self): msg = message.Message('update', self.state()) self.server.broadcast(msg)
def client_connected(self): print 'client connected: joining as', self.name msg = message.Message('join', {"name": self.name}) self.client.send_message(msg)
def add_watcher(self, watcher): self.clients.add(watcher) game_state = message.Message("update", self.game.state()) game_history = message.Message('history', {'todo': True}) watcher.send_message(bytes(str(game_state), 'utf-8')) watcher.send_message(bytes(str(game_history), 'utf-8'))