Created
August 7, 2012 05:42
-
-
Save heapwolf/3282025 to your computer and use it in GitHub Desktop.
tcp/pipe-server
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 net = require('net'); | |
var fs = require('fs'); | |
var path = require('path'); | |
var sock; | |
var port = 8089; | |
var log = path.join(__dirname + '/log.txt'); | |
var gol = path.join(__dirname + '/gol.txt'); | |
if (process.argv[2] === 'server') { | |
sock = new net.createServer(function(socket) { | |
socket.pipe(fs.createWriteStream(log)); | |
}).listen(port); | |
} | |
else { | |
sock = new net.Socket(); | |
fs.createReadStream(gol).pipe(sock.connect(port)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment