2017-04-28 11:54:08 -06:00
2017-04-28 11:54:08 -06:00
2017-04-28 11:29:30 -06:00
2017-04-28 11:54:08 -06:00

StreamPair

NPM version

A pair of coupled Unix sockets (or Windows pipes).

Similar to stream-pair, but with sockets with real fds. A workaround for https://github.com/nodejs/node/issues/12716.

Usage

var socketPair = require('socket-pair');

socketPair.create(function (err, pair) {
  var a = pair.client;      // as in `client = net.connect()`
  var b = pair.connection;  // as in `server.on('connection', function (conn) { ... })`

  a.write('123');
  b.on('data', function (chunk) {
    console.log(chunk.toString('utf8'));
  });

  socketPair.closeAll();
});

I named them client and connection, but their names really have no meaning.

You can call them a and b or other and one or red and blue. It makes no difference.

API

socketPair.create(cb)     // creates or reuses a socket server
socketPair.closeAll()     // closes the server and all sockets
Description
No description provided
Readme 31 KiB
Languages
JavaScript 100%