9

Since specifying the clienID is only a feature in the class MqttAndroidClient, and can not be specified when using classes IMqttClient and IMqttAsynchClient.

what is the real purpose of connecting a client with a unique ID?

1 Answer 1

17

Every MQTT Connection needs a unique client ID. With this unique client ID the broker can recognize when a client reconnects and can close an old potentially half-open TCP connection for the client. Also, the MQTT broker can hold a persistent session for MQTT clients if they desire to do so (cleanSession=false on CONNECT). If you disconnect and reconnect with the same client ID, you will receive all messages for your subscriptions you may have missed and the broker knows your old subscriptions for that client ID.

5
  • Thank you a lt for the informatio. but when i try to use IMqqttClient class r IMqtttAsynchClient class, there is no way provded to specify he clientID or the IP. i have cecked the internet for any example for the aforementioned classes to see how one can specify ID and IP but there is no such examples. any guidance or advise?
    – rmaik
    Nov 28, 2014 at 7:39
  • They are interfaces and cannot be instantiated. Nov 28, 2014 at 8:30
  • @AlessandroDaRugna maybe this could be a questin for you :) stackoverflow.com/questions/27174271/…
    – rmaik
    Nov 28, 2014 at 9:40
  • @Dominik Obermaier maybe you can answer his question as well stackoverflow.com/questions/27397417/…
    – rmaik
    Dec 10, 2014 at 10:26
  • specs for both 3.1 and 5.0 say that the server will handle this for you if client_id is empty so if we're talking about implementation, the client_id can be left empty and unassigned.
    – dtc
    Mar 7, 2023 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.