Skip to content

Instantly share code, notes, and snippets.

@joeegan
Created September 3, 2012 17:53
Show Gist options
  • Select an option

  • Save joeegan/3611355 to your computer and use it in GitHub Desktop.

Select an option

Save joeegan/3611355 to your computer and use it in GitHub Desktop.
simple tcp server that writes the data posted to it to an output file
var fs = require('fs'),
net = require('net');
var writeStream = fs.createWriteStream(__dirname + "/outfile.txt");
var server = net.createServer(function (socket) {
socket.on('data', function(data) {
socket.write(data);
writeStream.write(data);
console.log(data);
});
});
server.listen(1337, "localhost");
console.log("TCP server listening on port 1337 at localhost.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment