150
E. Fraccaroli and D. Quaglia
Message Type
DUP
QoS Level
RETAIN
Remaining Lenght (1 - 4 bytes)
Optional: Variable Length Header
Optional: Variable Length Message Payload
Fixed
Header
0
1
2
3
4
5
6
7
Bit Field
Fig. 3.28 MQTT packet structure
brokers which are configured to accept anonymous clients (i.e., username and
password are simply left blank).
MQTT is designed to be a lightweight protocol where all the messages have a
small code footprint. The structure of an MQTT message is shown in Fig. 3.28. Each
MQTT message consists of a 2 byte fixed header, followed by an optional variable
header, a message payload that is limited to 256 MB of information. Fourteen types
of MQTT messages can be exchanged [82]:
1. CONNECT: After a Client establishes a Network Connection to a Server, the first
Packet sent from the Client to the Server MUST be a CONNECT Packet.
2. CONNACK: Is sent by the Server in response to a CONNECT Packet received
from a Client.
3. PUBLISH: Is sent from a Client to a Server or from Server to a Client to
transport an Application Message.
4. PUBACK: Is the response to a PUBLISH Packet with QoS level 1.
5. PUBREC: Is the response to a PUBLISH Packet with QoS 2. It is the second
packet of the QoS 2 protocol exchange.
6. PUBREL: Is the response to a PUBREC Packet. It is the third packet of the QoS
2 protocol exchange.
7. PUBCOMP: The PUBCOMP Packet is the response to a PUBREL Packet. It is
the fourth and final packet of the QoS 2 protocol exchange.
8. SUBSCRIBE: The SUBSCRIBE Packet is sent from the Client to the Server to
create one or more Subscriptions. Each Subscription registers a Client’s interest
in one or more Topics. The Server sends PUBLISH Packets to the Client in order
to forward Application Messages that were published to Topics that match these
Subscriptions. The SUBSCRIBE Packet also specifies (for each Subscription)
the maximum QoS with which the Server can send Application Messages to the
Client.
9. SUBACK: A SUBACK Packet is sent by the Server to the Client to confirm
receipt and processing of a SUBSCRIBE Packet. A SUBACK Packet contains
a list of return codes that specifies the maximum QoS level that was granted in
each Subscription that was requested by the SUBSCRIBE.
Précédent

- 158/647

Suivant