Skip to content

Instantly share code, notes, and snippets.

@pedrofaria
Created October 19, 2010 20:44
Show Gist options
  • Save pedrofaria/635072 to your computer and use it in GitHub Desktop.
Save pedrofaria/635072 to your computer and use it in GitHub Desktop.
var net = require('net');
var global = [];
net.createServer(function (socket) {
socket.setEncoding("utf8");
socket.on('connect', function() {
socket.write("Echo server - "+ socket.fd +"\r\n");
});
socket.on("data", function (data) {
try {
var x = JSON.parse(data);
socket.write(JSON.stringify(x));
}
catch (err) {
socket.write('Unkown command... you suck!\r\n');
}
});
socket.on("end", function () {
socket.end();
});
}).listen(8124, "127.0.0.1");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment