1.0.2 • Published 8 years ago

unix-stream v1.0.2

Weekly downloads
5
License
ISC
Repository
github
Last release
8 years ago

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 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');
    });
});

Bitdeli Badge

1.0.2

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.5

10 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

12 years ago

0.0.1

12 years ago