muxpit
v0.2.0
Published
minimal multiplex interface using rpc-stream
Downloads
4
Readme
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
andonchannel
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