unix-stream

Unix stream socket

npm install unix-stream
10 downloads in the last week
18 downloads in the last month

Build Status

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 a remotePath getter and a path() functions that implement a similar functionality to remoteAddress and address() for unix stream sockets.

Example

var net = require('net');
var fs = require('fs');
var unix = require('../src/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.path() + " connected to: " + this.remotePath);
    });

    socket.on('data', function(data) {
        console.log('Data received by client: ' + data);
        socket.end('pong');
    });
});

Bitdeli Badge

npm loves you