Пример #1
0
    def __init__(self, host, port, is_async_connect, is_encrypt=None):
        self.__host = host
        self.__port = port
        self._callback_executor = CallbackExecutor()
        self._net_mgr = NetManager.default()
        self._handler_ctx = HandlerContext(self._is_proc_run)
        self._lock = RLock()
        self._status = ContextStatus.START
        self._connect_err = None  # rsa加密失败时为Err.RsaErr, 否则为str
        self._proc_run = True
        self._sync_req_ret = None
        self._sync_conn_id = 0
        self._conn_id = 0
        self._keep_alive_interval = 10
        self._last_keep_alive_time = datetime.now()
        self._reconnect_timer = None
        self._reconnect_interval = 8  # 重试连接的间隔
        self._sync_query_connect_timeout = None
        self._keep_alive_fail_count = 0
        self._is_encrypt = is_encrypt
        if self.is_encrypt():
            assert SysConfig.INIT_RSA_FILE != '', Err.NotSetRSAFile.text
        self._net_mgr.start()

        if not is_async_connect:
            self._socket_reconnect_and_wait_ready()

            while True:
                with self._lock:
                    if self._status == ContextStatus.READY or self._status == ContextStatus.CLOSED:
                        break
                sleep(0.02)
        else:
            self._wait_reconnect(0)
Пример #2
0
 def __init__(self, host, port, async_enable):
     self.__host = host
     self.__port = port
     self.__async_socket_enable = async_enable
     self._net_mgr = NetManager.default()
     self._handler_ctx = HandlerContext(self._is_proc_run)
     self._lock = RLock()
     self._status = ContextStatus.Start
     self._proc_run = True
     self._sync_req_ret = None
     self._sync_conn_id = 0
     self._conn_id = 0
     self._keep_alive_interval = 10
     self._last_keep_alive_time = datetime.now()
     self._reconnect_timer = None
     self._keep_alive_fail_count = 0
     self._net_mgr.start()
     self._socket_reconnect_and_wait_ready()
     while True:
         with self._lock:
             if self._status == ContextStatus.Ready:
                 break
         sleep(0.02)