Make Streams identifyable over to the Connection where it comes out #20

Closed
geNAZt opened this Issue Jan 24, 2013 · 4 comments

Projects

None yet

2 participants

@geNAZt

It would be nice if a Stream has a property which holds a connection identifier, so that i can hold all Streams of a Connection in one Container. The goal is to pipe two Streams that come out of two different Connections matching the stream meta tag.

@dominictarr
Owner

hmm, can you describe a concrete example where you would use this?

I'm not sure what you mean by "pipe two Streams that come out of two different Connections matching the stream meta tag", can you try that statement differently?

@geNAZt

If i take your example:

var MuxDemux = require('..')
var net = require('net')

var mdm1 = MuxDemux()

var mdm2 = 
  MuxDemux(function (stream) {
    stream.on('data', console.log.bind(console))
  })

net.createServer(function (con) {
  con.pipe(mdm2).pipe(con)
}).listen(8642, function () {
  var con = net.connect(8642)
  con.pipe(mdm1).pipe(con)
  var ds = mdm1.createWriteStream('times')

  setInterval(function () {
    ds.write(new Date().toString())
  }, 1e3)
})

And then let three Clients( a, b, c ) connect with 3 Streams( a, b and c ) and i want that Client a Stream a pipes to Client c Stream a via Stream piping.

@dominictarr
Owner

oh, oops! that example is misleading for using more than one stream at a time.
Instead, it should be created inside the connection handler.

I have corrected the readme example! sorry!

var MuxDemux = require('mux-demux')
var net = require('net')

net.createServer(function (con) {
  con.pipe(MuxDemux(function (stream) {
    stream.on('data', console.log.bind(console))
  })).pipe(con)
}).listen(8642, function () {
  var con = net.connect(8642), mx
  con.pipe(mx = MuxDemux).pipe(con)
  var ds = mx.createWriteStream('times')

  setInterval(function () {
    ds.write(new Date().toString())
  }, 1e3)
})

with this style it's not necessary to pipe to track the connection, because each connection gets it's own mux-demux.

@geNAZt

Ah okay thanks

@geNAZt geNAZt closed this Jan 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment