| | |
| | | # 发送心跳 |
| | | cls.__heartbeats_thread(type, key, sk) |
| | | cls.__listen_command_thread(type, key, sk) |
| | | print("create_and_run_client success",type,key) |
| | | return key, sk |
| | | |
| | | @classmethod |
| | |
| | | if _type == CLIENT_TYPE_TRADE: |
| | | if client_id in cls.trade_client_dict: |
| | | cls.trade_client_dict.pop(client_id) |
| | | print("pop trade client", client_id) |
| | | elif _type == CLIENT_TYPE_MONEY: |
| | | cls.money_client = None |
| | | elif _type == CLIENT_TYPE_DEAL_LIST: |
| | |
| | | json.dumps({"type": "heart", "client_id": client_id}).encode('utf-8'))) |
| | | # print("心跳信息发送成功", client_id) |
| | | except Exception as e: |
| | | print("心跳信息发送失败") |
| | | print("心跳信息发送失败",_type,client_id) |
| | | logging.exception(e) |
| | | if _type == CLIENT_TYPE_TRADE: |
| | | if client_id in cls.trade_client_dict: |
| | |
| | | while True: |
| | | try: |
| | | if len(cls.trade_client_dict) < cls.trade_client_count: |
| | | print("__maintain_client", CLIENT_TYPE_TRADE) |
| | | print("__maintain_client", CLIENT_TYPE_TRADE, cls.trade_client_count - len(cls.trade_client_dict)) |
| | | for i in range(cls.trade_client_count - len(cls.trade_client_dict)): |
| | | result = cls.__create_and_run_client(CLIENT_TYPE_TRADE) |
| | | cls.trade_client_dict[result[0]] = result[1] |