public void updateConnection(String clientId, String host, int port, boolean tlsConnection){ String uri; if(tlsConnection) { uri = "ssl://" + host + ":" + port; } else { uri = "tcp://" + host + ":" + port; } this.clientId = clientId; this.host = host; this.port = port; this.tlsConnection = tlsConnection; this.client = new MqttAndroidClient(context, uri, clientId); }
/** * Creates a connection from persisted information in the database store, attempting * to create a {@link MqttAndroidClient} and the client handle. * @param clientId The id of the client * @param host the server which the client is connecting to * @param port the port on the server which the client will attempt to connect to * @param context the application context * @param tlsConnection true if the connection is secured by SSL * @return a new instance of <code>Connection</code> */ public static Connection createConnection(String clientHandle, String clientId, String host, int port, Context context, boolean tlsConnection){ String uri; if(tlsConnection) { uri = "ssl://" + host + ":" + port; } else { uri = "tcp://" + host + ":" + port; } MqttAndroidClient client = new MqttAndroidClient(context, uri, clientId); return new Connection(clientHandle, clientId, host, port, context, client, tlsConnection); }
public void testHAConnect() throws Exception{ String methodName = "testHAConnect"; IMqttAsyncClient client = null; try { try { String junk = "tcp://junk:123"; client = new MqttAndroidClient(mContext, junk, methodName); String[] urls = new String[]{"tcp://junk", mqttServerURI}; MqttConnectOptions options = new MqttConnectOptions(); options.setServerURIs(urls); Log.i(methodName, "HA connect"); IMqttToken connectToken = client.connect(options); connectToken.waitForCompletion(waitForCompletionTime); Log.i(methodName, "HA disconnect"); IMqttToken disconnectToken = client.disconnect(null, null); disconnectToken.waitForCompletion(waitForCompletionTime); Log.i(methodName, "HA success"); } catch (Exception e) { e.printStackTrace(); throw e; } } finally { if (client != null) { client.close(); } } }
public void testHAConnect() throws Throwable{ String methodName = "testHAConnect"; IMqttAsyncClient client = null; try { try { String junk = "tcp://junk:123"; client = new MqttAndroidClient(mContext, junk, methodName); String[] urls = new String[]{"tcp://junk", serverURI}; MqttConnectOptions options = new MqttConnectOptions(); options.setServerURIs(urls); Log.i(methodName,"HA connect"); IMqttToken connectToken = client.connect(options, null, new ActionListener(notifier)); notifier.waitForCompletion(waitForCompletionTime); Log.i(methodName,"HA disconnect"); IMqttToken disconnectToken = client.disconnect(null, new ActionListener(notifier)); notifier.waitForCompletion(waitForCompletionTime); Log.i(methodName,"HA success"); } catch (Exception e) { e.printStackTrace(); throw e; } } finally { if (client != null) { client.close(); } } }
mqttClient = new MqttAndroidClient(mContext, serverURI, methodName); IMqttToken connectToken; IMqttToken subToken; mqttClient.close(); mqttClientRetained = new MqttAndroidClient(mContext, serverURI, "Retained");
String methodName = "testQoSPreserved"; mqttClient = new MqttAndroidClient(mContext, serverURI, "testQoSPreserved"); MqttV3Receiver mqttV3Receiver = new MqttV3Receiver(mqttClient, null);
IMqttAsyncClient mqttClient = null; try { mqttClient = new MqttAndroidClient(mContext, serverURI, methodName); IMqttToken connectToken; IMqttToken subToken;
mqttClient = new MqttAndroidClient(mContext, mqttSSLServerURI, "testSSLPubSub");
mqttClient = new MqttAndroidClient(mContext, mqttSSLServerURI, "testSSLConnect");
mqttClient = new MqttAndroidClient(mContext, mqttSSLServerURI, "testSSLConnect");
mqttClient = new MqttAndroidClient(mContext, mqttSSLServerURI, "testSSLPubSub");
public void testConnect() throws Throwable { IMqttAsyncClient mqttClient = null; mqttClient = new MqttAndroidClient(mContext, serverURI, "testConnect"); IMqttToken connectToken = null; IMqttToken disconnectToken = null; connectToken = mqttClient.connect(null, new ActionListener(notifier)); notifier.waitForCompletion(waitForCompletionTime); disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier)); notifier.waitForCompletion(waitForCompletionTime); connectToken = mqttClient.connect(null, new ActionListener(notifier)); notifier.waitForCompletion(waitForCompletionTime); disconnectToken = mqttClient.disconnect(null, new ActionListener(notifier)); notifier.waitForCompletion(waitForCompletionTime); }
mqttClient = new MqttAndroidClient(mContext, mqttServerURI, "testQoSPreserved"); MqttV3Receiver mqttV3Receiver = new MqttV3Receiver(mqttClient, null);
IMqttAsyncClient mqttClient = null; try { mqttClient = new MqttAndroidClient(mContext, mqttServerURI, methodName); IMqttToken connectToken; IMqttToken subToken;
/** * Tests that a client can be constructed and that it can connect to and * disconnect from the service * * @throws Exception */ public void testConnect() throws Exception { IMqttAsyncClient mqttclient = null; try { mqttclient = new MqttAndroidClient(mContext,mqttServerURI, "testConnect"); IMqttToken connectToken = null; IMqttToken disconnectToken = null; connectToken = mqttclient.connect(null, null); connectToken.waitForCompletion(waitForCompletionTime); disconnectToken = mqttclient.disconnect(null, null); disconnectToken.waitForCompletion(waitForCompletionTime); connectToken = mqttclient.connect(null, null); connectToken.waitForCompletion(waitForCompletionTime); disconnectToken = mqttclient.disconnect(null, null); disconnectToken.waitForCompletion(waitForCompletionTime); } catch (Exception exception){ fail("Failed: " + "testConnect" + " exception= " + exception); } finally { if(mqttclient != null){ mqttclient.close(); } } }
/** * Tests isConnected() returns false after a disconnect() call. * @throws Exception */ public void testIsConnected() throws Exception { IMqttAsyncClient mqttClient = null; try { mqttClient = new MqttAndroidClient(mContext, mqttServerURI, "testConnect"); IMqttToken connectToken = null; IMqttToken disconnectToken = null; assertFalse(mqttClient.isConnected()); connectToken = mqttClient.connect(null, null); connectToken.waitForCompletion(waitForCompletionTime); assertTrue(mqttClient.isConnected()); disconnectToken = mqttClient.disconnect(null, null); disconnectToken.waitForCompletion(waitForCompletionTime); assertFalse(mqttClient.isConnected()); } finally { if (mqttClient != null) { mqttClient.close(); } } }
IMqttAsyncClient mqttClient = null; try { mqttClient = new MqttAndroidClient(mContext, serverURI, "testLargeMessage"); IMqttToken connectToken;
IMqttAsyncClient mqttClient = null; mqttClient = new MqttAndroidClient(mContext, serverURI, "testRemoteConnect"); IMqttToken connectToken = null; IMqttToken subToken = null;
IMqttAsyncClient mqttClient = null; try { mqttClient = new MqttAndroidClient(mContext, mqttServerURI, "testLargeMessage"); IMqttToken connectToken;
IMqttAsyncClient mqttClient = null; try { mqttClient = new MqttAndroidClient(mContext, mqttServerURI, "testRemoteConnect"); IMqttToken connectToken = null; IMqttToken subToken = null;