socket.io icon indicating copy to clipboard operation
socket.io 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