3

按照 Jeremy Gooch 的说明,请参阅http://goochgooch.co.uk/2014/08/01/building-mosquitto-1-4/,我在 RPi 上的 websockets 上安装了 mosquitto。我可以将消息子/发布到测试站点http://test.mosquitto.org/ws.html

从那时起,我在 mosquitto.conf 中启用了用户和主题访问控制以进行更多测试,但奇怪的是,当我再次启动 mosquitto 时,我每秒看到套接字错误......

sudo /usr/local/sbin/mosquitto -v -c /etc/mosquitto/mosquitto.conf

 1429857948: mosquitto version 1.4 (build date 2015-04-20 22:04:51+0800) starting
1429857948: Config loaded from /etc/mosquitto/mosquitto.conf.
1429857948: Opening ipv4 listen socket on port 1883.
1429857948: Opening ipv6 listen socket on port 1883.
1429857948: Warning: Address family not supported by protocol
1429857949: New connection from 127.0.0.1 on port 1883.
1429857949: Sending CONNACK to 127.0.0.1 (0, 5)
1429857949: Socket error on client <unknown>, disconnecting.
1429857950: New connection from 127.0.0.1 on port 1883.
1429857950: Sending CONNACK to 127.0.0.1 (0, 5)
...

我修改配置文件以仅启用 ACL,注释掉所有其他的,套接字错误仍然存​​在。配置文件现在看起来:

sudo nano /etc/mosquitto/mosquitto.conf

autosave_interval 1800
persistence true
persistence_file m2.db
persistence_location /var/tmp/
connection_messages true
log_timestamp true
log_dest stderr
log_type error
log_type warning
log_type debug

allow_anonymous false
password_file /etc/mosquitto/mqtt.pw
acl_file /etc/mosquitto/mqtt.acl

port 1883
protocol mqtt

我什至测试使用示例 password_file 和 acl_file,但同样的错误。google了一下,也没有结果,有大神帮忙看看吗?谢谢。

4

2 回答 2

8

1429857949:向 127.0.0.1 (0, 5) 发送 CONNACK

CONNACK 返回码 5 表示连接未经授权。如果它与allow_anonymous = true一起使用,那么听起来您的客户端没有发送用户名/或没有发送正确的用户名和密码。

看起来您正在运行一个 Paho Python 客户端。

于 2015-04-24T20:44:17.957 回答
0

我遇到了同样的问题,我的解决方案是我没有关闭连接。一旦我添加了 client.Disconnect() 它就解决了我的问题。

代码:

public IEnumerator ooverhere()
{
    MqttClient client;
    client = new MqttClient(urlPath, port, false, MqttSslProtocols.None, null, null);
    client.ProtocolVersion = MqttProtocolVersion.Version_3_1;

    byte code = client.Connect(Guid.NewGuid().ToString(), user, pass);
    if (code == 0)
    {
        Debug.Log("successful connection ...");

        //client.MqttMsgPublishReceived += client_recievedMessage;

        Debug.Log("your client id is: " + client.ClientId);

        client.Subscribe(new string[] { "example" }, new byte[] { 0 });
        client.Publish("Helpme", Encoding.UTF8.GetBytes("@" + 0));
        yield return client;

        client.Disconnect();
    }
}
于 2018-04-26T13:32:01.523 回答