MQTT:在特定的 client_id 上一次又一次地断开连接

Pra*_*ngh 0 mqtt mosquitto

我面临特定 client_id 断开连接的问题。当我尝试连接时,它会突然断开连接并显示错误

1450599983: New connection from 192.168.2.245 on port 1883.
1450599983: Client 46144 disconnected.
1450599983: New client connected from 192.168.2.245 as 46144 (c0, k60).
1450599984: Socket error on client 46144, disconnecting.
Run Code Online (Sandbox Code Playgroud)

我的conf.d文件是

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d
cleansession true
Run Code Online (Sandbox Code Playgroud)

有时会在发送消息后发生。为什么会发生这种情况,我们该如何解决这个问题?

谢谢

ral*_*ght 5

听起来您有多个客户端使用相同的 clientid 连接。每个客户端的 clientid 必须是唯一的,如果客户端与现有客户端具有相同的 id,则代理会断开旧客户端的连接。如果您在 mosquitto 上启用完整日志记录,它会告诉您何时发生这种情况。