Skip to content

Instantly share code, notes, and snippets.

@heapwolf
Created August 7, 2012 05:43
Show Gist options
  • Save heapwolf/3282052 to your computer and use it in GitHub Desktop.
Save heapwolf/3282052 to your computer and use it in GitHub Desktop.
tcp/pipe-to-fs
var net = require('net');
var fs = require('fs');
var path = require('path');
var sock;
var port = 8089;
var log = path.join(__dirname + '/log.txt');
if (process.argv[2] === 'server') {
  sock = new net.createServer(function(socket) {
    socket.pipe(fs.createWriteStream(log));
  }).listen(port);
}
else {
  process.stdin.resume();
  sock = new net.Socket();
  sock.connect(port);
  process.stdin.on('data', function(d) {
    sock.write(d);
  });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment