Skip to content

Instantly share code, notes, and snippets.

@dcoder2099
Created July 21, 2010 01:08
Show Gist options
  • Save dcoder2099/483884 to your computer and use it in GitHub Desktop.
Save dcoder2099/483884 to your computer and use it in GitHub Desktop.
// This is a TCP server which listens at 127.0.0.1:8203
// All it does is log everything sent across the wire to the console.
// Send ^D as first char of buffer to shut down.
var net = require('net');
var CONTROL_D = String.fromCharCode(4);
net.createServer(function (socket) {
socket.setEncoding("utf8");
socket.write("Logging Test Server\r\n");
socket.on("data", function (data) {
console.log(data);
if (data.charCodeAt(0) == 4) {
socket.write('^D received, hasta!\r\n')
socket.end();
}
});
socket.on("end", function () {
socket.end();
});
}).listen(8203, "127.0.0.1");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment