MQTT return codes

When a MQTT broker (server) receives a CONNECT message from a client, it has to reply with a CONNACK message.

The CONNACK message contains a flag which returns a return code. This tells whether the connection attempt is successful or not. Here are the return codes:

Return CodeResponse
0Connection accepted
1Connection refused: level of MQTT protocol not supported by server.
2Connection refused: client identifier not allowed by server.
3Network connection successful but MQTT service is unavailable.
4Data in username or password is malformed.
5Client not authorized to connect.
6-255Reserved for future use.

http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718035