multiplex-stream-muxer

    0.2.0 • Public • Published

    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

    Install

    npm i multiplex-stream-muxer

    DownloadsWeekly Downloads

    1

    Version

    0.2.0

    License

    MIT

    Last publish

    Collaborators

    • daviddias