10

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?

4

1 回答 1

13

每个 MQTT 连接都需要一个唯一的客户端 ID。使用这个唯一的客户端 ID,代理可以识别客户端何时重新连接,并可以为客户端关闭一个旧的可能半开的 TCP 连接。此外,如果 MQTT 客户端愿意,MQTT 代理可以保持持久会话(在 CONNECT 上为cleanSession=false)。如果您使用相同的客户端 ID 断开连接并重新连接,您将收到您可能错过的订阅的所有消息,并且代理知道您对该客户端 ID 的旧订阅。

于 2014-11-27T17:29:53.257 回答