def TokenId(self, token_id): global client_token_id print('Get Sever token_id {}'.format(token_id)) self.token_id = token_id client_token_id = token_id conn_client = ConnectService.Client(self.protocol) conn_client.TokenId(self.token_id)
def client_closed(self, oprot): client = ConnectService.Client(oprot) client_md5 = get_md5(str(oprot)) client_list_tmp.pop(client_md5) if client_md5 in client_list.keys(): client_list.pop(client_md5) print('Delete client oprot == {}'.format(client_md5))
def cmd_client_process(protocol, cmdstr=None): try: conn_client = ConnectService.Client(protocol) cmd = CommandMsg() cmd.cmdstr = cmdstr while True: conn_client.Command(cmd) time.sleep(3) except TTransport.TTransportException as tx: print("cmd_client_process Error TTransport.TTransportException == {}". format(tx)) except Exception as x: print("Error Exeption == {}".format(x))
def Ping(self, token_id, time): try: print('Get client ping.............. {} '.format(token_id)) if token_id in client_list.keys(): if client_list[token_id].trans.isOpen(): client = ConnectService.Client(client_list[token_id]) int_time = int(dt.datetime.now().timestamp() - dt.datetime.utcfromtimestamp(0).timestamp()) client.Ping(token_id, int_time) except TTransport.TTransportException as tx: print("2222222 Ping Error TTransport.TTransportException == {}". format(tx)) except Exception as x: print("Error Exeption == {}".format(x))
def client_connected(self, oprot): global client_list_tmp try: client = ConnectService.Client(oprot) client_md5 = get_md5(str(oprot)) client_list_tmp[client_md5] = oprot if oprot.trans.isOpen(): client.TokenId(client_md5) print('Client.token_id called {}'.format(client_md5)) except TTransport.TTransportException as tx: print( "1111111 client_connected Error TTransport.TTransportException == {}" .format(tx)) except Exception as x: print("Error Exeption == {}".format(x))
def do_command_call(): global client_list try: while True: client_tmp_list = client_list.copy() for token_id in client_tmp_list.keys(): client = ConnectService.Client(client_tmp_list[token_id]) int_time = int(dt.datetime.now().timestamp() - dt.datetime.utcfromtimestamp(0).timestamp()) client.Ping(token_id, int_time) time.sleep(1) time.sleep(1) except TTransport.TTransportException as tx: print("do_command_call Error TTransport.TTransportException == {}". format(tx)) except Exception as x: print("Error Exeption == {}".format(x))