def onMessage(self, payload, isBinary): # if isBinary: # print("Binary message received: {0} bytes".format(len(payload))) # else: # print("Text message received: {0}".format(payload.decode('utf8'))) msg = payload.decode('utf8') ftlog.debug('ws onMessage', msg) _countProtocolPack(1, self) self._runTasklet(data=msg)
def onMessage(self, payload, isBinary): # if isBinary: # print("Binary message received: {0} bytes".format(len(payload))) # else: # print("Text message received: {0}".format(payload.decode('utf8'))) msg = payload.decode('utf8') ftlog.debug('ws onMessage', msg) _countProtocolPack(1, self) self._runTasklet(data=msg)
def lineReceived(self, data): if performance.PERFORMANCE_NET: data = performance.linkMsgTime('LR', data) ftlog.debug('S2AProtocol->lineReceived', FTTasklet.concurrent_task_count, time(), data) src, dst, query_id, userheader1, userheader2, msg = agentmsg.unpack(data) if ide_debug(): ide_print_pack("S2AP Recv [%5s]" % src.split("-")[0], json.loads(msg)) if src is None or dst is None: ftlog.info("ERROR, recive a error format message") return if self.peer_id == 0: self.peer_id = src ftcon.serverid_protocol_map[self.peer_id] = self ftlog.info('receive register, agentid=', self.peer_id) return _countProtocolPack(1, self) # send过来的数据 if query_id == '': self._runTasklet(data=msg, src=src, dst=dst, userheader1=userheader1, userheader2=userheader2, time_recv=time()) else: querysrc, _ = query_id.split('.') server_id = ftcon.global_config["server_id"] # query本服务的请求 if querysrc != server_id: self._runTasklet(data=msg, src=src, dst=dst, query_id=query_id, userheader1=userheader1, userheader2=userheader2, time_recv=time()) # response回来的请求 else: if userheader1 == 'RQ': # 本进程内, 异步查询本进程的其他消息接口 self._runTasklet(data=msg, src=src, dst=dst, query_id=query_id, userheader1=userheader1, userheader2=userheader2, time_recv=time()) else: d, c, t = None, None, 0 # ftlog.debug('lineReceived', query_id, id(_LIVE_MESSAGES), id(self)) if query_id in _LIVE_MESSAGES: d, c, t = _LIVE_MESSAGES[query_id] del _LIVE_MESSAGES[query_id] else: if query_id in _FAILED_MESSAGES: del _FAILED_MESSAGES[query_id] ftlog.warn('QUERY TOO SLOW !!', query_id, msg) if len(_FAILED_MESSAGES) > 100: _FAILED_MESSAGES.clear() else: ftlog.warn('NOT KNOW of query_id->', query_id, msg) if d and c: try: c.cancel() d.callback((msg, t, time())) except: ftlog.error(msg)
def lineReceived(self, data): ftlog.debug('S2AProtocol->lineReceived', data) src, dst, query_id, userheader1, userheader2, msg = agentmsg.unpack(data) if src == None or dst == None: ftlog.info("ERROR, recive a error format message") return if self.peer_id == 0: self.peer_id = src ftcon.serverid_protocol_map[self.peer_id] = self ftlog.info('receive register, agentid=', self.peer_id) return _countProtocolPack(1, self) # send过来的数据 if query_id == '': self._runTasklet(data=msg, src=src, dst=dst, userheader1=userheader1, userheader2=userheader2) else: querysrc, _ = query_id.split('.') server_id = ftcon.global_config["server_id"] # query本服务的请求 if querysrc != server_id: self._runTasklet(data=msg, src=src, dst=dst, query_id=query_id, userheader1=userheader1, userheader2=userheader2) # response回来的请求 else: if userheader1 == 'RQ': # 本进程内, 异步查询本进程的其他消息接口 self._runTasklet(data=msg, src=src, dst=dst, query_id=query_id, userheader1=userheader1, userheader2=userheader2) else: d, c = None, None # ftlog.debug('lineReceived', query_id, id(_LIVE_MESSAGES), id(self)) if query_id in _LIVE_MESSAGES: d, c = _LIVE_MESSAGES[query_id] del _LIVE_MESSAGES[query_id] else: if query_id in _FAILED_MESSAGES: del _FAILED_MESSAGES[query_id] ftlog.warn('QUERY TOO SLOW !!', query_id, msg, 'left bad querids=', _FAILED_MESSAGES) if len(_FAILED_MESSAGES) > 100: _FAILED_MESSAGES.clear() else: ftlog.warn('NOT KNOW of query_id->', query_id, msg) if d and c: try: c.cancel() d.callback(msg) except: ftlog.error(msg)
def lostHandler(self, reason): ''' TCP链接断开处理 ''' try: if self in _NEW_PROTOCOLS: del _NEW_PROTOCOLS[self] if self.userId > 0: ftlog.info('TCP lostHandler clientAddress=', self.clientAddress, 'userId=', self.userId, 'reason=', reason) # 异步进行用户断开连接的后续处理, 避免阻挡主tasklet data = '{"cmd":"conn_lost","params":{"userId":%d}}' % ( self.userId) _countProtocolPack(1, self) self._runTasklet(data=data) except: ftlog.error('lostHandler:')
def lineReceived(self, data): if performance.PERFORMANCE_NET: data = performance.linkMsgTime('LR', data) _countProtocolPack(1, self) self._runTasklet(data=data, time_recv=time())
def lineReceived(self, data): data = ftenc.code(self.encry_seed + int(data[:4], 16), data[4:]) data = zlib.decompress(data) _countProtocolPack(1, self) self._runTasklet(data=data)
def lineReceived(self, data): if performance.PERFORMANCE_NET: data = performance.linkMsgTime('LR', data) _countProtocolPack(1, self) self._runTasklet(data=data, time_recv=time())
def lineReceived(self, data): if performance.PERFORMANCE_NET: data = performance.linkMsgTime('LR', data) ftlog.debug('S2AProtocol->lineReceived', FTTasklet.concurrent_task_count, time(), data) src, dst, query_id, userheader1, userheader2, msg = agentmsg.unpack( data) if ide_debug(): ide_print_pack("S2AP Recv [%5s]" % src.split("-")[0], json.loads(msg)) if src is None or dst is None: ftlog.info("ERROR, recive a error format message") return if self.peer_id == 0: self.peer_id = src ftcon.serverid_protocol_map[self.peer_id] = self ftlog.info('receive register, agentid=', self.peer_id) return _countProtocolPack(1, self) # send过来的数据 if query_id == '': self._runTasklet(data=msg, src=src, dst=dst, userheader1=userheader1, userheader2=userheader2, time_recv=time()) else: querysrc, _ = query_id.split('.') server_id = ftcon.global_config["server_id"] # query本服务的请求 if querysrc != server_id: self._runTasklet(data=msg, src=src, dst=dst, query_id=query_id, userheader1=userheader1, userheader2=userheader2, time_recv=time()) # response回来的请求 else: if userheader1 == 'RQ': # 本进程内, 异步查询本进程的其他消息接口 self._runTasklet(data=msg, src=src, dst=dst, query_id=query_id, userheader1=userheader1, userheader2=userheader2, time_recv=time()) else: d, c, t = None, None, 0 # ftlog.debug('lineReceived', query_id, id(_LIVE_MESSAGES), id(self)) if query_id in _LIVE_MESSAGES: d, c, t = _LIVE_MESSAGES[query_id] del _LIVE_MESSAGES[query_id] else: if query_id in _FAILED_MESSAGES: del _FAILED_MESSAGES[query_id] ftlog.warn('QUERY TOO SLOW !!', query_id, msg) if len(_FAILED_MESSAGES) > 100: _FAILED_MESSAGES.clear() else: ftlog.warn('NOT KNOW of query_id->', query_id, msg) if d and c: try: c.cancel() d.callback((msg, t, time())) except: ftlog.error(msg)