Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
mux-demux and dnode, my brain is boiling and can't see why it's not working
var dnode = require('dnode')
var MuxDemux = require('mux-demux')
var net = require('net')
var client = MuxDemux()
var d = dnode()
d.on('remote', function (remote) {
console.log('in remote')
remote.foo(function (p) {
console.log(p)
})
})
client.on('connection', function (c) {
console.log('connection' + c.meta)
if (c.meta == 'dnode') {
d.pipe(c).pipe(d)
}
})
client.pipe(net.connect(3000)).pipe(client)
var dnode = require('dnode')
var d = dnode.connect(3000)
d.on('remote', function (remote) {
console.log('in remote')
remote.foo(function (p) {
console.log(p)
})
})
var dnode = require('dnode')
var MuxDemux = require('mux-demux')
var net = require('net')
var server = MuxDemux()
var d = dnode({
foo: function (cb) {
cb(['bla', 'dude'])
}
})
d.pipe(server.createStream('dnode')).pipe(d)
net.createServer(function (client) {
client.pipe(server).pipe(client)
}).listen(3000)
var dnode = require('dnode')
var d = dnode({
foo: function (cb) {
cb(['bla', 'dude'])
}
})
d.listen(3000)
@nakosung

This comment has been minimized.

Copy link

commented Jul 19, 2013

I had the same problem before. According to node.js doc, stream's behavior is somewhat strange. The mux-demux stream which was created in server-nope.js is resumed before got piped thru 'client' stream. This causes to drop off dnode's initial handshake packets. To remedy this situation there are two possible solutions.
#1 : Do not create mux demux stream before.

  • move your mux-demux, dnode code inside net.createServer function() { ## HERE ## }.
    #2 : Pause your mux-demux stream and resume when you need it.
  • server.pause() after line 5, server.resume() after line 14.
@nakosung

This comment has been minimized.

Copy link

commented Jul 20, 2013

check my gist : https://gist.github.com/nakosung/6044876

pause-stream can be a cure for unpausable mux-demux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.