def sendMsg(self, cmd, data): try: Logger.debug_network('==== SEND TCP TO %s:' % self.peer_key, '%08X' % cmd, repr(data)) if self.transport and self.connected: header = struct.pack('II', cmd, len(data)) self.transport.write(header + data) return True else: Logger.error('==== ERROR: cannot connected !! protocol =', self, '%08X' % cmd, repr(data)) except Exception, e: Logger.exception(data)
def connectionLost(self, reason=connectionDone): try: Logger.info('ConnectionLost', 'userId =', self.userId) if self.userId > 0: msg = MsgPack(Message.MSG_INNER_BROKEN) if self.userId in Context.GData.map_client_connect: del Context.GData.map_client_connect[self.userId] msg.set_param('userId', self.userId) if self.gameId > 0: msg.set_param('gameId', self.gameId) tasklet = self.makeTasklet(Message.MSG_INNER_BROKEN, msg, self) TaskManager.add_task(tasklet.run) else: Logger.debug_network('empty user connection lost ... ') except Exception, e: Logger.exception()