/** * Connects to an MQTT server using the default options. * <p> * The default options are specified in {@link MqttConnectOptions} class. * </p> * * @throws MqttException * for any connected problems * @return token used to track and wait for the connect to complete. The * token will be passed to the callback methods if a callback is * set. * @see #connect(MqttConnectOptions, Object, IMqttActionListener) */ @Override public IMqttToken connect() throws MqttException { return connect(null, null); }
/** * Connects to an MQTT server using the provided connect options. * <p> * The connection will be established using the options specified in the * {@link MqttConnectOptions} parameter. * </p> * * @param options * a set of connection parameters that override the defaults. * @throws MqttException * for any connected problems * @return token used to track and wait for the connect to complete. The * token will be passed to any callback that has been set. * @see #connect(MqttConnectOptions, Object, IMqttActionListener) */ @Override public IMqttToken connect(MqttConnectOptions options) throws MqttException { return connect(options, null, null); }
/** * Connects to an MQTT server using the default options. * <p> * The default options are specified in {@link MqttConnectOptions} class. * </p> * * @param userContext * optional object used to pass context to the callback. Use null * if not required. * @param callback * optional listener that will be notified when the connect * completes. Use null if not required. * @throws MqttException * for any connected problems * @return token used to track and wait for the connect to complete. The * token will be passed to any callback that has been set. * @see #connect(MqttConnectOptions, Object, IMqttActionListener) */ @Override public IMqttToken connect(Object userContext, IMqttActionListener callback) throws MqttException { return connect(new MqttConnectOptions(), userContext, callback); }
public void connect(Connection connection) { String[] actionArgs = new String[1]; actionArgs[0] = connection.getId(); final ActionListener callback = new ActionListener(this, ActionListener.Action.CONNECT, connection, actionArgs); connection.getClient().setCallback(new MqttCallbackHandler(this, connection.handle())); try { connection.getClient().connect(connection.getConnectionOptions(), null, callback); } catch (MqttException e) { Log.e(this.getClass().getCanonicalName(), "MqttException occurred", e); } }
mqttAndroidClient.connect(mqttConnectOptions, null, new IMqttActionListener() { @Override public void onSuccess(IMqttToken asyncActionToken) {
drawerFragment.updateConnection(connection); connection.getClient().connect(connOpts, null, callback); Fragment fragment = new ConnectionFragment(); Bundle bundle = new Bundle();
connection.getClient().connect(connOpts, null, callback); Fragment fragment = new ConnectionFragment(); Bundle bundle = new Bundle();
/** * Connects to an MQTT server using the default options. * <p> * The default options are specified in {@link MqttConnectOptions} class. * </p> * * @throws MqttException * for any connected problems * @return token used to track and wait for the connect to complete. The * token will be passed to the callback methods if a callback is * set. * @see #connect(MqttConnectOptions, Object, IMqttActionListener) */ @Override public IMqttToken connect() throws MqttException { return connect(null, null); }
/** * Connects to an MQTT server using the default options. * <p> * The default options are specified in {@link MqttConnectOptions} class. * </p> * * @throws MqttException * for any connected problems * @return token used to track and wait for the connect to complete. The * token will be passed to the callback methods if a callback is * set. * @see #connect(MqttConnectOptions, Object, IMqttActionListener) */ @Override public IMqttToken connect() throws MqttException { return connect(null, null); }
/** * Connects to an MQTT server using the provided connect options. * <p> * The connection will be established using the options specified in the * {@link MqttConnectOptions} parameter. * </p> * * @param options * a set of connection parameters that override the defaults. * @throws MqttException * for any connected problems * @return token used to track and wait for the connect to complete. The * token will be passed to any callback that has been set. * @see #connect(MqttConnectOptions, Object, IMqttActionListener) */ @Override public IMqttToken connect(MqttConnectOptions options) throws MqttException { return connect(options, null, null); }
/** * Connects to an MQTT server using the provided connect options. * <p> * The connection will be established using the options specified in the * {@link MqttConnectOptions} parameter. * </p> * * @param options * a set of connection parameters that override the defaults. * @throws MqttException * for any connected problems * @return token used to track and wait for the connect to complete. The * token will be passed to any callback that has been set. * @see #connect(MqttConnectOptions, Object, IMqttActionListener) */ @Override public IMqttToken connect(MqttConnectOptions options) throws MqttException { return connect(options, null, null); }
IMqttToken disconnectToken = null; connectToken = mqttClient.connect(options, this.getContext(), new ActionListener(notifier)); connectToken.waitForCompletion(waitForCompletionTime); disconnectToken.waitForCompletion(waitForCompletionTime); connectToken = mqttClient.connect(options, this.getContext(), new ActionListener(notifier)); connectToken.waitForCompletion(waitForCompletionTime);
/** * 连接MQTT服务器 */ public void connect(IEasyMqttCallBack starMQTTCallBack) { this.starMQTTCallBack = starMQTTCallBack; if (canDoConnect && !client.isConnected()) { try { client.connect(conOpt,null, iMqttActionListener); } catch (Exception e) { e.printStackTrace(); } } }
mqttClient.setCallback(mqttV3Receiver); connectToken = mqttClient.connect(options,this.getContext(),new ActionListener(notifier)); connectToken.waitForCompletion(waitForCompletionTime);
MqttAndroidClient mqttClient = new MqttAndroidClient(BaseApplication.getAppContext(), broker, MQTT_CLIENT_ID); //Set call back class mqttClient.setCallback(new MqttCallbackHandler(BaseApplication.getAppContext())); MqttConnectOptions connOpts = new MqttConnectOptions(); IMqttToken token = mqttClient.connect(connOpts);
mqttClient.setCallback(mqttV3Receiver); connectToken = mqttClient.connect(options); connectToken.waitForCompletion(waitForCompletionTime);
/** * Connects to an MQTT server using the default options. * <p> * The default options are specified in {@link MqttConnectOptions} class. * </p> * * @param userContext * optional object used to pass context to the callback. Use null * if not required. * @param callback * optional listener that will be notified when the connect * completes. Use null if not required. * @throws MqttException * for any connected problems * @return token used to track and wait for the connect to complete. The * token will be passed to any callback that has been set. * @see #connect(MqttConnectOptions, Object, IMqttActionListener) */ @Override public IMqttToken connect(Object userContext, IMqttActionListener callback) throws MqttException { return connect(new MqttConnectOptions(), userContext, callback); }
/** * Reconnect the selected client */ private void reconnect() { Connections.getInstance(context).getConnection(clientHandle).changeConnectionStatus(ConnectionStatus.CONNECTING); Connection c = Connections.getInstance(context).getConnection(clientHandle); try { c.getClient().connect(c.getConnectionOptions(), null, new ActionListener(context, Action.CONNECT, clientHandle, null)); } catch (MqttSecurityException e) { Log.e(this.getClass().getCanonicalName(), "Failed to reconnect the client with the handle " + clientHandle, e); c.addAction("Client failed to connect"); } catch (MqttException e) { Log.e(this.getClass().getCanonicalName(), "Failed to reconnect the client with the handle " + clientHandle, e); c.addAction("Client failed to connect"); } }
public MqttAndroidClient getMqttClient(Context context, String brokerUrl, String clientId) { mqttAndroidClient = new MqttAndroidClient(context, brokerUrl, clientId); try { IMqttToken token = mqttAndroidClient.connect(getMqttConnectionOption()); token.setActionCallback(new IMqttActionListener() { @Override public void onSuccess(IMqttToken asyncActionToken) { mqttAndroidClient.setBufferOpts(getDisconnectedBufferOptions()); Log.d(TAG, "Success"); } @Override public void onFailure(IMqttToken asyncActionToken, Throwable exception) { Log.d(TAG, "Failure " + exception.toString()); } }); } catch (MqttException e) { e.printStackTrace(); } return mqttAndroidClient; }