java - MQTT协议的消息类型, 可以如何分类?
PHPz
PHPz 2017-04-17 16:34:01
0
1
1013
PHPz
PHPz

学习是最好的投资!

reply all(1)
左手右手慢动作

1. First of all, what you list is the definition of message type in the fixed header of the message distributed by the server in the MQTT protocol.

In fact, this is unified in most open source implementations and has no practical significance. It is mainly based on these types to do some business processing. For example, when you receive a request to connect MQTT_CONNECT时候,初始化资源;
在断开连接MQTT_DISCONNECT, you do some finishing work, such as finding that the connection has been disconnected in the app, and actively pushing a message to the app to tell the app that the connection has been disconnected and messages cannot be sent;

2. To truly implement business message types, you need to customize them yourself. Define the message type in the payload. Payload is the real business message entity.
For example, customization:

{
//文本
  message : 1,
  content : "你好",
  time    : "2016-2-1"
}
{
//图片
  message : 2,
  content : "www.baidu.com/image/img.jpg",
  time    : "2016-2-1"
}

Of course, you mainly define the required message type and format based on your own business needs, then convert the above data into data, and place the data in the payload for distribution.

I have just come into contact with the MQTT protocol, and I am doing subscription and distribution on iOS. A superficial understanding provides an idea for mutual exchange and learning.
On github, I compiled some materials: https://github.com/wenghengcong/MQTTExplore.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template