使用mqtt测试服务器测试mqtt 8883 匿名加密通信
mqtt 8883 通信采用加密,不需要验证(匿名)的方法,不使用密码登录。
1.下载mosquitto.org的证书。
wget https://test.mosquitto.org/ssl/mosquitto.org.crt
2.订阅命令
mosquitto_sub -L mqtts://test.mosquitto.org:8883/const.net.cn/ --cafile mosquitto.org.crt -d
Client (null) sending CONNECT
Client (null) received CONNACK (0)
Client (null) sending SUBSCRIBE (Mid: 1, Topic: const.net.cn/, QoS: 0, Options: 0x00)
Client (null) received SUBACK
Subscribed (mid: 1): 0
设置Qos为2
mosquitto_sub -L mqtts://test.mosquitto.org:8883/const.net.cn/ --cafile mosquitto.org.crt -q 2 -d
Client (null) sending CONNECT
Client (null) received CONNACK (0)
Client (null) sending SUBSCRIBE (Mid: 1, Topic: const.net.cn/, QoS: 2, Options: 0x00)
Client (null) received SUBACK
Subscribed (mid: 1): 2
Client (null) sending CONNECT
Client (null) received CONNACK (0)
Client (null) sending SUBSCRIBE (Mid: 2, Topic: const.net.cn/, QoS: 2, Options: 0x00)
Client (null) received SUBACK
Subscribed (mid: 2): 2
3.发布命令
mosquitto_pub -L mqtts://test.mosquitto.org:8883/const.net.cn/ --cafile mosquitto.org.crt -m 'mqtt hello world test.mosquitto.org 8883 : MQTT, encrypted, unauthenticated' -d
Client (null) sending CONNECT
Client (null) received CONNACK (0)
Client (null) sending PUBLISH (d0, q0, r0, m1, 'const.net.cn/', ... (75 bytes))
Client (null) sending DISCONNECT
4、接收内容
Client (null) received PUBLISH (d0, q0, r0, m0, 'const.net.cn/', ... (75 bytes))
mqtt hello world test.mosquitto.org 8883 : MQTT, encrypted, unauthenticated
Client (null) sending PINGREQ
Client (null) received PINGRESP
注意,mosquitto心跳包默认时长为60秒,可以通过-k参数设置。
-k : keep alive in seconds for this client. Defaults to 60.