var mqtt = require('mqtt')
var options = {
username: 'abc',
password: 'xyz',
}
var client = mqtt.connect('mqtt:localhost:1883', options);
function authenteClient() {
// I need to call this function against the callback at server's
// authenticate function.
}
在上面的代码中,我在此 mqtt 客户端的选项中提供用户名和密码。
var mosca = require('mosca');
var ascoltatore = {
type: 'mongo',
url: 'mongodb://localhost:27017/mqtt',
pubsubCollection: 'ascoltatori',
mongo: {}
};
var settings = {
port: 1883,
backend: ascoltatore
};
var server = new mosca.Server(settings);
server.on('ready', setup);
function setup() {
server.authenticate = authenticate;
console.log('Mosca server is up and running');
}
var authenticate = function(client, username, password, callback) {
console.log(username, password);
callback(true);
}
在authenticate
函数的服务器端,我需要在客户端连接一个回调,该回调在那里被调用为callback(true)
.