node-unix-stream
At the moment, node does not support unix stream connections from a socket bound to a local path. As stated in https://github.com/joyent/node/issues/3705, it likely won't be supported as Windows doesn't have this feature.
This module adds this functionality and expands net.Socket to add localPath and remotePath getters and a path() functions that implement a similar functionality to localAddress and remoteAddress and address() for unix stream sockets.
Installation
npm install unix-stream
Example
var net = require('net');
var fs = require('fs');
var unix = require('unix-stream');
// Create Unix socket Server bound to /tmp/remote_path
if (fs.existsSync('/tmp/remote_path')) {
fs.unlinkSync('/tmp/remote_path');
}
var server = net.createServer(function(con) {
console.log("[Server] Client connected from: " + con.remotePath);
con.write('ping');
con.on('data', function(data) {
console.log('Data received by server: ' + data);
});
con.on('end', function() {
server.close();
});
});
server.listen('/tmp/remote_path', function() {
// Create Unix socket bound to /tmp/local_path
if (fs.existsSync('/tmp/local_path')) {
fs.unlinkSync('/tmp/local_path');
}
var socket = unix.createSocket('/tmp/local_path');
socket.on('error', function(err) {
console.log(err);
});
// Connect to /tmp/remote_path
socket.connect({ path : '/tmp/remote_path' }, function() {
console.log("[Client] Client bound to: " + this.localPath +
" connected to: " + this.remotePath);
});
socket.on('data', function(data) {
console.log('Data received by client: ' + data);
socket.end('pong');
});
});