0

在下面的代码片段中,我为订阅声明了一个usernameand passqord

private final String userName = "user_1";
private final char[] password = "pass".toCharArray();
....
....
final MqttAndroidClient client_1 = new MqttAndroidClient(getApplicationContext(), serverURI,   
clientID, persistenceDataDir, Ack.AUTO_ACK);
MqttConnectOptions opts = new MqttConnectOptions();
opts.setCleanSession(false);
opts.setWill(WILL_TOPIC, WILL_MSG.getBytes(), QoS, false);
opts.setKeepAliveInterval(keepAliveInterval);
opts.setUserName(userName);
opts.setPassword(password);

我从应用程序开始连接,clean session = false无论client ID = 1是否提供密码和用户名,我一直发布(从 PC 到代理)我订阅的主题的值(从应用程序到代理。

稍后在subscribe消息中,我在连接选项中设置了密码和用户名,并没有指定publish消息的用户名和密码,然后重新运行 p。发生的事情是,我收到了我订阅的主题的更新发布值。

之后,publish我指定了错误的用户名和密码并订阅了相同的主题,当我运行应用程序时,我会正常收到值。

我用错了密码和用户名?

注意:我已经尝试了不同的相同程序,clientID即使指定了错误的密码,我也会收到发布的值。

4

1 回答 1

0

您需要设置一个 acl 文件和一个密码文件,以便使用用户名和密码来控制对主题的访问。

请阅读 mosquitto.conf 和 mosquitto_passwd 手册页以了解这两个文件的格式的详细信息

http://mosquitto.org/man/mosquitto-conf-5.html

http://mosquitto.org/man/mosquitto_passwd-1.html

于 2014-11-19T23:25:11.087 回答