8

In MQTT it is the client who initiates the connection with a CONNECT message.

MQTT Connect Package parameters

The first field of the packet is the clientId:

The client identifier (short ClientId) is an identifier of each MQTT client connecting to a MQTT broker. As the word identifier already suggests, it should be unique per broker. The broker uses it for identifying the client and the current state of the client. (Image and quote are taken from from here.)

Now let's say I have two clients, client X and Y in the following situation.

  1. Broker launched, no clients yet.
  2. X succesfully connects to the broker with client-1 id, username is X.
  3. Now, Y tries to connect using client-1 as id, username is Y.

What will happen?

  1. Based on the clientId, the broker will think that X performs a repeated connection attempt which is abnormal behavior.
  2. Nothing extraordinary will happen. Y connects successfully as it uses a different username.
  3. Nothing extraordinary will happen. The broker will reject Y connection attempt as the given clientId is already in use.
Helmar
  • 8,450
  • 6
  • 36
  • 84
Bence Kaulics
  • 7,843
  • 8
  • 42
  • 90

1 Answers1

6

If the clientid is the same, in MQTT, the spec says you must consider them to be the same client! Probably Y should be connected using the Id and X should be disconnected.

This part is from the documentation:

If validation is successful the Server performs the following steps.

  1. If the ClientId represents a Client already connected to the Server then the Server MUST disconnect the existing Client [MQTT-3.1.4-2].

  2. The Server MUST perform the processing of CleanSession that is described in section 3.1.2.4 [MQTT-3.1.4-3].

  3. The Server MUST acknowledge the CONNECT Packet with a CONNACK Packet containing a zero return code [MQTT-3.1.4-4].

  4. Start message delivery and keep alive monitoring.

Look this documentation for more details.

ThisaruG
  • 824
  • 6
  • 16