-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connect to unix socket #1040
Comments
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 <notifications@github.com>, 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: #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 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 If this issue is still important, you can simply comment with a Thank you for your contribution. |
We're still interested in this! |
It's actually possible to connect to a '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. |
@rockey2020, there should NOT be any prefixes to the path, remove the |
I did a quick test and, apparently, compiled ts -> js output indeed changed drastically, so old simple method doesn't work anymore. 'use strict';
const net = require('node:net');
const mqtt = require('mqtt');
function streamBuilder() { return net.createConnection({ path: "/run/mosquitto/mosquitto.sock" }); };
function msgRecv(path, data, packet) { console.log("mqtt_msg_in: ['%s']:(%d) '%s'", path, data.length, data.toString()); };
const client = new mqtt.Client(streamBuilder, { username: "user", password: "pass" });
client.on('error', (err) => { if (!err) { return; }; console.error(err); client.end(); });
client.on('connect', (conn_evt) => {
console.log("mqtt: connected. Subscribing...");
client.subscribe(['#'], { nl: true }, (err, granted) => { console.log("granted:", granted); });
});
client.on('message', msgRecv); |
I think the problem is the |
May I suggest reopening this (or should I create a new issue?) for URI-based support, e.g. The idea is that it would allow various projects (I'm thinking about Zigbee2MQTT, which currently doesn't seem to have a way to specify Thanks! |
@drdaeman want to submit a PR? |
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 totcp.js
, but with this sort of construct instead:The text was updated successfully, but these errors were encountered: