mux-demux and dnode, my brain is boiling and can't see why it's not working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dnode = require('dnode') | |
var d = dnode({ | |
foo: function (cb) { | |
cb(['bla', 'dude']) | |
} | |
}) | |
d.listen(3000) |
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
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.
#2 : Pause your mux-demux stream and resume when you need it.