Skip to content

Instantly share code, notes, and snippets.

@ralphtheninja
Created March 13, 2013 05:22
Show Gist options
  • Select an option

  • Save ralphtheninja/5149566 to your computer and use it in GitHub Desktop.

Select an option

Save ralphtheninja/5149566 to your computer and use it in GitHub Desktop.
module.exports = function () {
var server = createMuxDemux()
var methods = {
protocols: function (cb) {
cb(getProtocols())
}
, open: function (protocol, cb) {
if (speaks(protocol)) {
var read = createStream(protocol)
var mux = server.createStream(protocol)
var path = '/home/magnus/client.txt'
var write = fs.createWriteStream(path)
read.pipe(mux)
mux.pipe(write)
mux.on('data', function (data) {
// this never happens
console.error('M <- ' + data.toString())
})
cb(null)
} else {
cb({ message: 'Invalid protocol', protocol: protocol })
}
}
}
var d = dnode(methods)
d.pipe(server.createStream('dnode')).pipe(d)
return server
}
@ralphtheninja
Copy link
Author

The server variable returned from the function is returned back to an ordinary tcp connection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment