When a TCP/IP socket connection is established between the client and the broker, a protocol level session is required. It is assumed that the direction of connection is client to broker, and that the client supports broker listener functionality.
The fixed header format is shown in the table below.
bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
---|---|---|---|---|---|---|---|---|
byte 1 | Message Type (1) | DUP flag | QoS level | RETAIN | ||||
0 | 0 | 0 | 1 | x | x | x | x | |
byte 2 | Remaining Length |
The DUP, QoS, and RETAIN flags are not used in the CONNECT message.
Remaining Length is the length of the variable header (12 bytes) and the length of the Payload. This can be a multibyte field.
An example of the format of the variable header is shown in the table below.
Description | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |
---|---|---|---|---|---|---|---|---|---|
Protocol Name | |||||||||
byte 1 | Length MSB (0) | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
byte 2 | Length LSB (6) | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 |
byte 3 | 'M' | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 |
byte 4 | 'Q' | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 1 |
byte 5 | 'I' | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 1 |
byte 6 | 's' | 0 | 1 | 1 | 1 | 0 | 0 | 1 | 1 |
byte 7 | 'd' | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 |
byte 8 | 'p' | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
Protocol Version Number | |||||||||
byte 9 | Version (3) | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 |
Connect Flags | |||||||||
byte 10 | Will RETAIN (0) |
x | x | 0 | 0 | 1 | 1 | 1 | x |
Keep Alive timer | |||||||||
byte 11 | Keep Alive MSB (0) | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
byte 12 | Keep Alive LSB (10) | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 |
The first UTF-encoded string. The Client Identifier (Client ID) is between 1 and 23 characters long, and uniquely identifies the client to the broker. It must be unique across all clients connecting to a single broker, and is the key in handling Message IDs messages with QoS levels 1 and 2. If the Client ID contains more than 23 characters, the broker responds to the CONNECT message with a CONNACK return code 2: Identifier Rejected.
The second UTF-encoded string. The Will Message is published to the Will Topic. The QoS level is defined by the Will QoS field, and the RETAIN status is defined by the Will RETAIN flag in the variable header.
The third UTF-encoded string. The Will Message defines the content of the message that is published to the Will Topic if the client is unexpectedly disconnected.
Although the Will Message is UTF-encoded in the CONNECT message, when it is published to the Will Topic only the bytes of the message are sent, not the first two length bytes. The message sent when the broker executes the Will Message is raw ASCII, not UTF-encoded.
The broker sends a CONNACK message in response to a CONNECT message from a client.
If the client does not receive a CONNACK message from the broker within a "reasonable" amount of time, the client closes the TCP/IP socket connection, and restarts the session by opening a socket to the broker and issuing a CONNECT message. A "reasonable" amount of time depends on the type of application and the communications infrastructure.
Notices |
Trademarks |
Downloads |
Library |
Support |
Feedback
![]() ![]() |
ac10910_ |