MQTT CONNECT header: 如何定义用户名和密码?
MQTT CONNECT header: how to define username and password?
我正在尝试从功能非常有限的设备向 MQTT 代理发送数据,因此我需要在通过 TCP/IP 发送之前手动构建我的请求。
我知道用户名和密码保存在消息负载中,但我不明白它们是如何分隔的。总长度在 header 中给出,但我看不到它到达代理后如何分解成不同的字符串。
有人可以帮我举一个有效的 CONNECT 请求的例子,并解释一下它的格式吗?
此页面提供了一个似乎有道理的概述,但缺少任何包含用户名和密码的示例。
http://www.steves-internet-guide.com/mqtt-protocol-messages-overview/
规范文档似乎也不是很有帮助,但我可能只是没有正确理解它。
http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html#connect
我是 Stack Overflow 的新手,所以如果我遗漏了什么或我的请求措辞不正确,请告诉我。
谢谢
您正在查看规范的旧版本。
完整的最新 spec for version 3.1.1 contains a definition of how the username and password is to be encoded in this section。
Each of these strings is prefixed with a two byte length field that gives the number of bytes in a UTF-8 encoded string itself, as illustrated in Figure 1.1 Structure of UTF-8 encoded strings below. Consequently there is a limit on the size of a string that can be passed in one of these UTF-8 encoded string components; you cannot use a string that would encode to more than 65535 bytes.
所以你有 2 个字节(组成一个 16 位数字)构成字符串的长度,后面是包含实际字符串的那么多字节。
用户名和密码均以此格式传输。
我正在尝试从功能非常有限的设备向 MQTT 代理发送数据,因此我需要在通过 TCP/IP 发送之前手动构建我的请求。
我知道用户名和密码保存在消息负载中,但我不明白它们是如何分隔的。总长度在 header 中给出,但我看不到它到达代理后如何分解成不同的字符串。
有人可以帮我举一个有效的 CONNECT 请求的例子,并解释一下它的格式吗?
此页面提供了一个似乎有道理的概述,但缺少任何包含用户名和密码的示例。 http://www.steves-internet-guide.com/mqtt-protocol-messages-overview/
规范文档似乎也不是很有帮助,但我可能只是没有正确理解它。 http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html#connect
我是 Stack Overflow 的新手,所以如果我遗漏了什么或我的请求措辞不正确,请告诉我。
谢谢
您正在查看规范的旧版本。
完整的最新 spec for version 3.1.1 contains a definition of how the username and password is to be encoded in this section。
Each of these strings is prefixed with a two byte length field that gives the number of bytes in a UTF-8 encoded string itself, as illustrated in Figure 1.1 Structure of UTF-8 encoded strings below. Consequently there is a limit on the size of a string that can be passed in one of these UTF-8 encoded string components; you cannot use a string that would encode to more than 65535 bytes.
所以你有 2 个字节(组成一个 16 位数字)构成字符串的长度,后面是包含实际字符串的那么多字节。
用户名和密码均以此格式传输。