Socket.io connects to the unix connector

I want to connect to a unix socket using socket.io-client, There is no success (mostly a timeout error, the last fetch is a dns resolution error).

var clientio  = require('socket.io-client');
// i tried all variants here
//client=clientio.connect('port.io/',{'force new connection': true});
//client=clientio.connect('unix://port.io/',{'force new connection': true});
//client=clientio.connect('http//unix:port.io/',{'force new connection': true});

client.on('connect',connect);

Is there a way to connect the socket.io client to a unix socket?

I checked the server socket with nc -U port.io, it works fine.

0
source share
3 answers

Just found this, looking for answers to a similar question.

AFAIK socket.io-clientdepends on engne.io-client, which depends on wswhich it contains:

var isUnixSocket = serverUrl.protocol === 'ws+unix:';

See here: https://github.com/websockets/ws/blob/4f99812b1095979afaad58865846b160334f3415/lib/WebSocket.js#L598 .

, , UNIX-, node.js( - ) - , -.

, - :

var client=clientio.connect('ws+unix:/port.io',{'force new connection': true});

: , socket.io engine.io UNIX:( UDS ws , , socket.io (, ).

+2

socket.io webSocket, TCP. Unix-, socket.io.

net.Socket, : http://nodejs.org/api/net.html, TCP UNIX ".

socket.io , , , . , socket.io .

- , , socket.io. . , , webSocket. Socket.io - webSocket.


. , Unix.

nodejs nodejs, socket.io, socket.io , , socket.io:

var socket = require('socket.io-client')('http://port.io');
socket.on('connect', function(){});
socket.on('event', function(data){});
socket.on('disconnect', function(){});

, port.io socket.io(-, DNS, ). , , , URL- HTTP, webSocket socket.io HTTP- URL- HTTP.

, URL Unix.

+1

, , , .

unix , , socket.io( WebSockets)

// Generated by CoffeeScript 1.9.2
var app, domain_server, fs, io, net, server;
fs = require('fs');
net = require('net');
app = require('express')();
server = require('http').Server(app);
io = require('socket.io')(server);

/* Handle Unix Domain Socket
 * * Delete file if it already exists, 
 *   avoiding EADDRINUSE  */

if (fs.existsSync('/tmp/domain_socket')) {
  fs.unlinkSync('/tmp/domain_socket');
}

domain_server = net.createServer(function(socket) {
  socket.on('data', function(data) {
    /* broadcast messages from unix socket to websockets */
    io.sockets.emit('domain-message', data.toString());
  });
});

domain_server.listen('/tmp/domain_socket', function() {
  console.log('domain_server bound');
});


/*
 * Handle Web Serving/WebSockets
 */

server.listen(8080);

app.get('/', function(req, res) {
  res.sendFile(__dirname + '/index.html');
});

io.on('connection', function(socket) {
  socket.emit('message', {
    hello: 'connected'
  });
});
0

Source: https://habr.com/ru/post/1535468/


All Articles