【发布时间】:2021-08-22 08:37:14
【问题描述】:
我正在创建一个使用 MQTT 实现的应用程序。为此,我必须使用特定的 clientId 登录到 MQTT 服务器,其中在 clientId 的初始部分中包含特定的字符串。使用这个 clientId,我无法通过代码端登录 MQTT 服务器。
但使用 MQTT-Explorer 软件,我可以使用相同的凭据登录。如果我从 clientId 更改任何单词或稍后更改,那么我可以通过代码端进行登录。
我尝试过各种库,但都没有成功。这可能是什么原因以及如何解决这个问题?
我遇到了错误。
mqtt.event.error connection failure Connection lost (32109) - java.io.EOFException
我使用了“react-native-mqtt-new”库,我的 MQTT createClient 和通信代码如下
import MQTT from 'react-native-mqtt-new';
MQTT.createClient({
uri: 'mqtt://mqtt.demo.io:1883', //for demo
clientId: 'specific_string_randomnumber', //for demo
user: 'xxxxx',
pass: 'xxxx',
tls: false
}).then(function (client) {
client.on('closed', function () {
console.log('mqtt.event.closed');
});
client.on('error', function (msg) {
console.log(client);
console.log('mqtt.event.error', msg);
});
client.on('message', function (msg) {
console.log('mqtt.event.message', msg);
});
client.on('connect', function () {
console.log('connected');
client.subscribe('test/#', 0);
client.publish('test', "demo", 0, false);
});
client.connect();
}).catch(function (err) {
console.log(err, 'err');
});
【问题讨论】:
-
edit 显示的是您得到的确切错误。
-
更新了错误。
-
客户端遇到什么错误?
-
您是否有权访问 MQTT Broker 错误日志?如果是这样,当登录不起作用时它会说什么?那里也应该有登录失败的日志记录。
标签: react-native authentication mqtt clientid