Introduction to MQTT (3) - Analysis of Packet

Since MQTT is a communication protocol, it is necessary to look at the packet message information during communication to help understand the protocol itself.

MQTT is a binary protocol, so the data in the message is bytecode instead of text.

And it uses command and command acknowledgement to communicate in pairs. (1) The MQTT message structure of the

message analysis standard is mainly divided into three parts: fixed header (Fixed Header), variable header (Variable Header), and payload (Payload). The fixed header is 2 bytes, and it will definitely exist. , other parts can be absent. The minimum packet contains two fields: control header and header length. The control header contains two fields: message type and flag bits. The variable header contains four fields: protocol name, protocol level, connection flag, and keepalive connection. The connection flag contains the following Eight fields: Bit 0: Retain Flag Bit 1: Clear Session Flag Bit 2: Will Flag Bit 3, 4: QoS Flag Bit 5: Will Retain Flag Bit 6: Password Bit 7: User Name (2) Packet capture Here, Wireshark is used to capture packets. You can enter mqtt in the filter column to view only the communication packets of mqtt. The following captures the most commonly used types of the 14 packets. You can refer to the analysis section above for one-to-one correspondence. connect CONNECT/connect confirm CONNACK


































Because the public and free Broker service is used, the Client ID, User name, and Password are all empty.



PUBLISH


MESSAGE SUBSCRIBE/SUBACK Ack SUBACK



Disconnect DISCONNECT


Reference:
http://www.steves-internet-guide.com/mqtt-protocol-messages-overview/
http://gitbook.cn/books/599e6ab53a09d014a0aba58b/ index.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326169485&siteId=291194637