Exemplo n.º 1
0
 protected static MQTT mqttClient(String host, int port) {
   MQTT client = new MQTT();
   client.setCleanSession(true);
   client.setClientId("amc-" + Thread.currentThread().getId() + "-" + System.currentTimeMillis());
   client.setHost(URIs.newURI("tcp://" + host + ":" + port));
   return client;
 }
Exemplo n.º 2
0
  private static FutureConnection createConnection(String host, String clientId) {

    try {
      MQTT client = new MQTT();
      client.setHost(host);
      client.setClientId(clientId);
      client.setCleanSession(false);
      return client.futureConnection();
    } catch (URISyntaxException e) {
      Log.e(logTag, e.getMessage());
      return null;
    }
  }
  public void createConnection() {
    // Public Queue
    mqtt = new MQTT();
    if ("".equals(user)) user = userText.getText().toString().trim();

    Log.i(TAG, user + "request" + new java.util.Date().getTime());
    mqtt.setClientId(user + "request" + new java.util.Date().getTime());
    // sAddress = "tcp://www.zeroglitch.org:1883";
    sAddress = "tcp://192.168.1.101:1883";
    sAddress = "tcp://www.zeroglitch.org:" + "1883"; // + port;

    Log.i(TAG, "Creating connection to " + sAddress);

    try {
      mqtt.setHost(sAddress);
      Log.d(TAG, "Address set: " + mqtt.getHost());
      Log.d(TAG, "client set: " + mqtt.getClientId());
    } catch (URISyntaxException urise) {
      Log.e(TAG, "URISyntaxException connecting to " + sAddress + " - " + urise);
    }

    Log.i(TAG, "the user: " + user);
  }
Exemplo n.º 4
0
 private MQTT newClient(MqttLinkConfig config) {
   MQTT client = new MQTT();
   client.setClientId(config.getClientId());
   client.setHost(URIs.newURI("tcp://" + config.getHost() + ":" + config.getPort()));
   return client;
 }