Skip to content

Instantly share code, notes, and snippets.

@fearofcode
Created August 21, 2011 21:47
Show Gist options
  • Save fearofcode/1161217 to your computer and use it in GitHub Desktop.
Save fearofcode/1161217 to your computer and use it in GitHub Desktop.
A toy node.js echo server that disconnects when given the input 'disconnect'
var net = require('net');
var server = net.createServer(function(socket) {
socket.on('data', function(data) {
socket.write(data);
var str = data.toString('utf8');
if(str.indexOf('disconnect') !== -1) {
socket.end('goodbye\n');
}
});
});
server.listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment