Skip to content

Instantly share code, notes, and snippets.

@beersheba
Created January 20, 2018 03:38
Show Gist options
  • Save beersheba/56678e4b978711b2789186b86468424f to your computer and use it in GitHub Desktop.
Save beersheba/56678e4b978711b2789186b86468424f to your computer and use it in GitHub Desktop.
private void connect() {
MqttConnectOptions connectOptions = new MqttConnectOptions();
connectOptions.setAutomaticReconnect(true);
client = new MqttAndroidClient(this, serverURI, clientId);
try {
client.connect(connectOptions, new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
subscribe();
}
@Override
public void onFailure(IMqttToken asyncActionToken, Throwable e) {
e.printStackTrace();
}
});
} catch (MqttException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment