0

This class IMqttClient() allows you to create a client object with a callback to all possible events to happen, for an example

@Override
public void subscribe(String arg0) throws MqttException, MqttSecurityException {

    // TODO Auto-generated method stub
}

@Override
public void setCallback(MqttCallback arg0) {

    // TODO Auto-generated method stub
}

@Override
public void publish(String arg0, byte[] arg1, int arg2, boolean arg3) throws MqttException, MqttPersistenceException {

    // TODO Auto-generated method stub
}

But this class does not allow you to specify an ID for each client. How that is possible? especially if you want to connect with clean session = false?

Also, i have checked the class MqttConnectOptions when you instantiate an object you can set the server URI as an option and later you can do something like that client.connect(opts), but there is no way to specify the ID.

Luciano Rodríguez
  • 2,239
  • 3
  • 19
  • 32
rmaik
  • 1,076
  • 3
  • 15
  • 48

2 Answers2

0

Paho Library provides an option to give the client Id in constructor itself while creating the object of Mqttclient:

Here is the syntax:

mClient = new MqttClient(Constant.serverLink, Constant.client_id, null);

You can provide the client over there.

Hope this helps you out!

Amit
  • 225
  • 2
  • 14
0

If you're using the libraries from com.ibm.mqtt.IMqttClient, you specify the clientId when you connect:

mqttClient.connect(clientId, cleanStart, keepAliveSeconds);

For more information, please refer to this documentation: http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html

If you're using another library, read the documentation. They will definitely allow you to specify a clientId. It would be quite useless not to have one since you wouldn't be able to do anything other than broadcasting without it.

kha
  • 19,123
  • 9
  • 34
  • 67