IOT-MQTT protocol - Control packets -CONNACK

3.2 CONNACK - a connection request acknowledgment

CONNACK server response packet is a packet transmitted from the CONNECT packet received from the client. Sent from the server to the client a packet must be the first packet CONNACK  [the MQTT-3.2.0-1] .

If the client does not receive packets from the server CONNACK within a reasonable period of time, the client network connection should be closed. "Reasonable" amount of time depends on the type and communications infrastructure applications.

Fixed 3.2.1 Fixed header title

Fixed header format shown in FIG. 3.8 - CONNACK Packet fixed header .

FIG. 3.8 - CONNACK Packet Glands

Place

7

6

5

4

3

2

1

0

 Byte 1

MQTT control packet type (2)

reserved

 

0

0

1

0

0

0

0

0

Byte 2

The remaining length (2)

 

0

0

0

0

0

0

1

0

The remaining length field

This is a variable length header. For CONNACK Packet, which is 2

3.2.2 Variable header variable header

Variable header format shown in Figure 3.9 - CONNACK Packet variable header .

FIG. 3.9 - CONNACK Packet header variables

 

description

7

6

5

4

3

2

1

0

Connection confirmation flag Connect Acknowledge Flags

reserved

SP 1

Byte 1

 

0

0

0

0

0

0

0

X

Connecting the return code

Byte 2

Connect Return code

X

X

X

X

X

X

X

X

3.2.2.1 Connect Acknowledge Flags connection confirmation flag

Byte 1 is "Connect Acknowledge Flags". 7-1 Reserved bits must be set to 0. Bit 0 (SP 1) is present flag session.  

3.2.2.2 Session Present 

Location: Bit 0 Connect Acknowledge Flags of. 
If the server accepts the connection CleanSession to 1, the data packet except CONNACK  in [MQTT-3.2.2-1] is provided outside the return code of zero, the server must be set to 0 in the Session Present CONNACK packet.
If the server accepts the connection CleanSession to 0, the value set in the Present Session Server depends on whether the state has been stored Session ID provided by the client. If the server stores session state, it must be included in the data CONNACK  [MQTT-3.2.2-2]  will be set to 1 Session Present  .  If the server does not store session state, it must be set to 0 in the Session Present CONNACK packet. This return code is set to zero in the supplemental data packet CONNACK [the MQTT-3.2.2-3] .

Session Present flag enables the client to determine the client and server have a consistent view on whether the stored session state. 

After the initial setup of the session, the session state having a storage client server keeps its desired session state. If there is a session the client received from the server value is not in line with expectations, the client can choose whether to continue the conversation or disconnected. The client can be disconnected, to the Clean Session 1 and then dropped to disconnect the session state on the client and the server again. 
If the server sends a CONNACK packet contains a nonzero return code, you must set the Session Present 0  [the MQTT-3.2.2-4]  .

3.2.2.3 Connect Return code connected to the return code

2-byte variable header.

Table 3.1 - connect return code values listed in the return code field is connected one-byte unsigned value . If the server received good CONNECT packet format, but for some reason the server can not handle it, the server should try to transmit from the table contains the corresponding data packet CONNACK nonzero return code is connected. If the server sends a data packet CONNACK contains a nonzero return code, it must close Fi [the MQTT-3.2.2-5] .

Table 3.1 - return code value is connected

value

Return code in response to

description

0

0x00 Connection accepted

Accept connections

1

0x01 connection reject unacceptable protocol version

MQTT server does not support the protocol requested by the client level

2

0x02 connection is rejected, the identifier is denied

The client identifier is correct UTF-8, but the server does not allow

3

0x03 rejects the connection, the server is unavailable

Network connection is established but MQTT service is unavailable

4

0x04 Connection refused, user name or password is incorrect

User name or password is incorrect data format

5

0x05 Connection refused unauthorized

Client not authorized to connect

6-255

 

Reserved for future use

 

If Table 3.1 - Return Codes connection code values listed are applicable, then the server must be shut down without sending a network connection CONNACK  [the MQTT-3.2.2-6]  .

3.2.3 Payload Payload

CONNACK no packet payload.

Guess you like

Origin blog.csdn.net/leeahuamsg/article/details/93208692