绑定莫斯卡监听 IP 地址?



有没有办法只监听特定IP地址/主机名上的传入网络连接?最好通过在代码中动态传递 IP 地址/主机名,而不是编辑配置文件。

在 Mosca 的文档中找不到对此的引用 - http://www.mosca.io/docs/这就是我发布的原因。

谢谢你的时间。

它在这里的文档中。创建新的mosca.Server对象时,可以将hostport作为选项对象的一部分传入。

var pubsubsettings = {
//using ascoltatore
type: 'mongo',        
url: 'mongodb://localhost:27017/mqtt',
pubsubCollection: 'ascoltatori',
mongo: {}
};
var moscaSettings = {
port: 1883,           //mosca (mqtt) port
host: "127.0.0.1",
backend: pubsubsettings   //pubsubsettings is the object we created above 
};
var server = new mosca.Server(moscaSettings);   //here we start mosca
server.on('ready', setup);  //on init it fires up setup()
// fired when the mqtt server is ready
function setup() {
console.log('Mosca server is up and running')
}

最新更新