コード例 #1
0
    def connect(self):
        """Open the actual connection to the server (async).

        Returns:
            concurrent.futures.Future: Future which completes when connection succeeds or fails.
            If connection fails, Future will contain an exception.
            If connection succeeds, Future will contain a dict with the following members:

            * ['session_present'] (bool): is True if resuming existing session and False if new session.
        """
        future = Future()

        def on_connect(error_code, return_code, session_present):
            if return_code:
                future.set_exception(Exception(ConnectReturnCode(return_code)))
            elif error_code:
                future.set_exception(awscrt.exceptions.from_code(error_code))
            else:
                future.set_result(dict(session_present=session_present))

        try:
            _awscrt.mqtt_client_connection_connect(
                self._binding, self.client_id, self.host_name, self.port,
                self.socket_options, self.client.tls_ctx,
                self.reconnect_min_timeout_secs,
                self.reconnect_max_timeout_secs, self.keep_alive_secs,
                self.ping_timeout_ms, self.will, self.username, self.password,
                self.clean_session, on_connect, self.websocket_proxy_options)

        except Exception as e:
            future.set_exception(e)

        return future
コード例 #2
0
ファイル: mqtt.py プロジェクト: adolfogc/aws-crt-python
    def connect(self):
        future = Future()

        def on_connect(error_code, return_code, session_present):
            if return_code:
                future.set_exception(Exception(ConnectReturnCode(return_code)))
            elif error_code:
                future.set_exception(awscrt.exceptions.from_code(error_code))
            else:
                future.set_result(dict(session_present=session_present))

        try:
            _awscrt.mqtt_client_connection_connect(
                self._binding, self.client_id, self.host_name, self.port,
                self.socket_options, self.client.tls_ctx, self.keep_alive_secs,
                self.ping_timeout_ms, self.will, self.username, self.password,
                self.clean_session, on_connect, self.websocket_proxy_options)

        except Exception as e:
            future.set_exception(e)

        return future