0.2.0 • Published 9 years ago

muxpit v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

muxpit

minimal multiplex interface using rpc-stream.

example

var muxpit = require('muxpit');
var concat = require('concat-stream');
var net = require('net');

var server = net.createServer(function (stream) {
  var pit = muxpit(function (stream, id) {
    stream.end('warp riders');
  });
  stream.pipe(pit).pipe(stream);
});

server.listen(0, function () {
  var client = net.connect(server.address().port);

  var pit = muxpit();
  pit.pipe(client).pipe(pit);

  var stream = pit.open('some-id');
  stream.pipe(concat(function (body) {
    console.log(body.toString());
  }));
});

api

var muxpit = require('muxpit')

var pit = muxpit(opts, onchannel)

Returns a multiplex.

  • opts and onchannel are same as that of multiplex

pit.open(id, opts)

Creates and returns a shared stream. opts are same as that of multiplex.createSharedStream() and will be applied to both local and remote streams.

This method also emits an open event with (stream, id) at the other end.

license

mit