socket.io-client icon indicating copy to clipboard operation
socket.io-client copied to clipboard

Support for unix sockets

Open thejhh opened this issue 8 years ago • 5 comments

Websockets has a support for unix sockets with a url like ws+unix:///path/to/file, but Socket.io doesn't seem to support it.

The server:

const path = './server.sock';

var app = require('http').createServer(function(req, res) {
    console.log('Request for ' + req.url);
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('Hello World\n');
});

var io = require('socket.io')(app);

io.on('connection', function (socket) {
    socket.emit('news', { hello: 'world' });
    socket.on('my other event', function (data) {
        console.log(data);
    });
});

app.listen(path, function() {
    console.log(`Server running at ${path}`);
});

...and client:

const path = './server.sock';
var socket = require('socket.io-client')('ws+unix://' + require('path').resolve(path));
socket.on('connect', function(){
        console.log('connect');
});
socket.on('event', function(data){
        console.log('event: ', data);
});
socket.on('disconnect', function(){
        console.log('disconnect');
});

...but client doesn't connect...

thejhh avatar Jul 31 '16 23:07 thejhh

Have you switched to a different library since posting this?

emcniece avatar Oct 11 '16 23:10 emcniece

Who? Me?

thejhh avatar Oct 18 '16 19:10 thejhh

Yes @jheusala - just wondering if you solved this problem somehow or dropped it.

emcniece avatar Oct 18 '16 19:10 emcniece

No, I haven't solved it. I recall I just used normal HTTP network as a workaround. I would indeed use UNIX sockets if it were possible, and AFAIK there is no reason why it couldn't work. Unix sockets give better security since you can use simple file system permissions to control who has access to the service.

thejhh avatar Oct 19 '16 09:10 thejhh

@darrachequesne do you think it's worth to have a fix for this? I can work on this.

thoqbk avatar Apr 23 '19 01:04 thoqbk