Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Created July 12, 2012 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save max-mapper/3095611 to your computer and use it in GitHub Desktop.
Save max-mapper/3095611 to your computer and use it in GitHub Desktop.
mux-demux over http
var request = require('request')
var muxdemux = require('mux-demux')
var uri = "http://localhost:8080/listen"
var mux = muxdemux()
var stream = mux.createWriteStream('listen')
var req = request.post({uri: uri, json: true})
mux.pipe(req)
stream.write("")
var http = require('http')
http.createServer(function (req, res) {
var demux = muxdemux()
req.pipe(demux)
demux.on('connection', function(stream) {
console.log('stream', stream)
})
}).listen(8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment