我正在创建一个具有MQTT实现的应用程序。为此,我必须使用在clientId的初始部分包含特定字符串的特定clientId登录到MQTT服务器。使用这个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');
});发布于 2021-06-09 12:09:09
此问题已修复。这个问题的原因是我为了满足我的需求而使用的库。我们的需求是连接MQTT协议3.1.1和"react-native- MQTT -new“库,我们连接到MQTT协议3.1.0,这就是我收到错误的原因。
对于解决方案,我已经将库更改为"react-native-native-mqtt“,现在它可以正常工作了。
https://stackoverflow.com/questions/67834711
复制相似问题