MQTT.js
MQTT.js copied to clipboard
Connect to unix socket
Would you consider support for connecting to unix sockets? The use case is a local application wanting to connect to a local MQTT broker without having to create a network.
It looks like lib/connect/unix.js would be very similar to tcp.js, but with this sort of construct instead:
unixpath = '/var/run/mqtt.socket'
return net.createConnection(unixpath)
Definitely! I have no bandwidth to work on this, but I’ll be happy to review a PR Il 6 feb 2020, 13:03 +0100, Roger Light [email protected], ha scritto:
Would you consider support for connecting to unix sockets? The use case is a local application wanting to connect to a local MQTT broker without having to create a network. It looks like lib/connect/unix.js would be very similar to tcp.js, but with this sort of construct instead: unixpath = '/var/run/mqtt.socket'
return net.createConnection(unixpath) — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
Thanks, I'll take a look.
Any updates on this ? Would be interested in this feature too !
I hadn't done any more because of this: https://github.com/mqttjs/MQTT.js/pull/1094 , but that has been closed now for some reason. It wasn't clear what to use as the URL prefix, otherwise I suspect it may have got further.
I've been using my own modified version just fine, I'd be happy for anyone to take this over.
I suggest using unix:// prefix, which also used in nginx configs (those are really widespread and well known). Native mosquitto clients also use option --unix to specify path to unix socket.
I am really confused why it has not been accepted yet. This feature is clearly useful for security, doesn't break anything, and there is not that much to review! Literally 1 line of code and 1 file with 6 lines of really simple and straight-forward code added. Is project dead / in hibernation or what?
This is an automated message to let you know that this issue has gone 365 days without any activity. In order to ensure that we work on issues that still matter, this issue will be closed in 14 days.
If this issue is still important, you can simply comment with a "bump" to keep it open.
Thank you for your contribution.
We're still interested in this!
It's actually possible to connect to a unix socket right now.
Check this out:
'use strict';
const mqtt = require('mqtt');
const cfg = { path: "/run/mosquitto/mosquitto.sock", username: "user", password: "pass" };
const client = mqtt.connect(cfg);
client.on('error', (err) => { if (err) { console.error(err); }; });
client.on('connect', (conn_evt) => {
console.log("mqtt: connected. Subscribing...");
client.subscribe(['#'], { nl: true }, (err, granted) => { console.log("granted:", granted); });
});
client.on('message', (path, data, packet) => { console.log("mqtt_msg_in: ['%s']:(%d) '%s'", path, data.length, data.toString()); });
I dunno how that code could work @nik-sie, the PR adding unix socket support has never been merged. Maybe the default tcp handler could work as it support sockets too
@robertsLando, If you really want to use unix sockets, just try it, it works, I've been using it for a long time.
It works, since MqttClient uses node's native net.createConnection() call under the hood, which accepts path option (if given) to create connection to an IPC.
The PR would only add convenience of using URLs, that's it.