Created
August 21, 2011 21:47
-
-
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'
This file contains hidden or 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 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