us

unix-stream

Add bind support to node unix stream sockets

Showing:

Popularity

Downloads/wk

1

GitHub Stars

9

Maintenance

Last Commit

5yrs ago

Contributors

4

Package

Dependencies

2

Size (min+gzip)

1.7KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

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

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial