multiplex-stream-muxer
v0.2.0
Published
Abstraction on top of multiplex, implementing the abstract-stream-muxer interface
Downloads
5
Maintainers
Readme
multiplex-stream-muxer Node.js Implementation
Abstraction on top of multiplex, implementing the abstract-stream-muxer interface
Usage
multiplex-stream-muxer follows the abstract-stream-muxer API
Example
// Client.js
var MultiplexStreamMuxer = require('multiplex-stream-muxer')
var dialer = new MultiplexStreamMuxer()
var connDialer = dialer.attach(socket, false)
connDialer.dialStream(function (err, stream) {
t.ifError(err, 'Should not throw')
t.pass('dialed stream')
})
// Server.js
var MultiplexStreamMuxer = require('multiplex-stream-muxer')
var listener = new MultiplexStreamMuxer()
var connListener = listener.attach(socket, true)
connListener.on('stream', function (stream) {
t.pass('got stream')
})
You can also follow the net.connect pattern by listening to the ready
and error
events
var stream = connListener.dialStream()
stream.on('ready', function () {})
stream.on('error', function (err) {})
stream.write('buffer this') // this write will be buffered untill the socket is ready to transmit