socket.io-client
socket.io-client copied to clipboard
Support for unix sockets
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...
Have you switched to a different library since posting this?
Who? Me?
Yes @jheusala - just wondering if you solved this problem somehow or dropped it.
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.
@darrachequesne do you think it's worth to have a fix for this? I can work on this.