var self = this
self.logs.push('connect')
var mqtt = require('mqtt')
// #ifdef H5
var client = mqtt.connect('ws://127.0.0.1:61623',{
username:'admin',
password:'password',
clean:false,
clientId:'mqttjs_' + Math.random().toString(16).substr(2, 8)
})
// #endif
console.log(client);
client.on('connect', function() {
self.logs.push('on connect');
client.subscribe('chat/general', function(err) {
console.log(err);
if (!err) {
self.logs.push(err)
}
})
client.subscribe('month', function(err) {
if (!err) {
client.publish('month','Friday');
}
})
client.publish('year','2019');
client.publish('_bool',true);
}).on('reconnect', function() {
self.logs.push('on reconnect')
})
这是我的代码,为什么我要使用mqtt.js连接到频繁断开连接和重新连接的本地apache-apollo-1.7.1服务器?这是服务器配置问题吗?