private void connect(){
  if (!connected) {
    updateInfo();
    String connectString="tcp://" + connectAddress + ":"+ connectPort;
    if (clientId == null || clientId.length() < 1) {
      out(getDate() + Messages.MqttClientView_15 + connectString+ Messages.MqttClientView_16);
      return;
    }
    try {
      if (firstConnect) {
        mqttClient=new MqttClient(connectString,clientId);
        mqttClient.setCallback(this);
        firstConnect=false;
      }
    }
 catch (    MqttException e) {
      out(getDate() + Messages.MqttClientView_17 + e.getMessage());
      e.printStackTrace();
    }
    connOpts=new MqttConnectOptions();
    connOpts.setCleanSession(cleanStart);
    connOpts.setConnectionTimeout(30);
    connOpts.setKeepAliveInterval(keepAlive);
    if (username.length() > 0 && password.length() > 0) {
      connOpts.setPassword(password.toCharArray());
      connOpts.setUserName(username);
    }
    if (useWill) {
      if (willTopic == null || willTopic.equals("")) {
        out(Messages.MqttClientView_19);
        return;
      }
      connOpts.setWill(mqttClient.getTopic(willTopic),willMessage.getBytes(),willQos,willRetain);
    }
    try {
      out(getDate() + Messages.MqttClientView_20 + connectString);
      mqttClient.connect(connOpts);
      connected=true;
      out(getDate() + Messages.MqttClientView_21 + clientId);
    }
 catch (    MqttException e) {
      out(getDate() + Messages.MqttClientView_22 + e.getMessage());
      e.printStackTrace();
    }
  }
 else {
    out(Messages.MqttClientView_23);
  }
}

private void connect ( ) { if ( ! connected ) { updateInfo ( ) ; String connectString = "tcp://" + connectAddress + ":" + connectPort ; if ( clientId == null || clientId . length ( ) < 1 ) { out ( getDate ( ) + Messages . MqttClientView_15 + connectString + Messages . MqttClientView_16 ) ; return ; } try { if ( firstConnect ) { mqttClient = new MqttClient ( connectString , clientId ) ; mqttClient . setCallback ( this ) ; firstConnect = false ; } } catch ( MqttException e ) { out ( getDate ( ) + Messages . MqttClientView_17 + e . getMessage ( ) ) ; e . printStackTrace ( ) ; } connOpts = new MqttConnectOptions ( ) ; connOpts . setCleanSession ( cleanStart ) ; connOpts . setConnectionTimeout ( 30 ) ; connOpts . setKeepAliveInterval ( keepAlive ) ; if ( username . length ( ) > 0 && password . length ( ) > 0 ) { connOpts . setPassword ( password . toCharArray ( ) ) ; connOpts . setUserName ( username ) ; } if ( useWill ) { if ( willTopic == null || willTopic . equals ( "" ) ) { out ( Messages . MqttClientView_19 ) ; return ; } connOpts . setWill ( mqttClient . getTopic ( willTopic ) , willMessage . getBytes ( ) , willQos , willRetain ) ; } try { out ( getDate ( ) + Messages . MqttClientView_20 + connectString ) ; mqttClient . connect ( connOpts ) ; connected = true ; out ( getDate ( ) + Messages . MqttClientView_21 + clientId ) ; } catch ( MqttException e ) { out ( getDate ( ) + Messages . MqttClientView_22 + e . getMessage ( ) ) ; e . printStackTrace ( ) ; } } else { out ( Messages . MqttClientView_23 ) ; } }
connects to the broker
