Skip to content

Instantly share code, notes, and snippets.

@elvinio
Created February 15, 2015 13:54
Show Gist options
  • Save elvinio/9c5eed9399f2beac6869 to your computer and use it in GitHub Desktop.
Save elvinio/9c5eed9399f2beac6869 to your computer and use it in GitHub Desktop.
Node.js Socket Server
net.createServer(
function(sock) {
console.log("Received connection from " + sock.remoteAddress + ':' + sock.remotePort);
sock.on('data', function(data){
string = data.toString('ascii')
setTimeout(function(){
sock.write(data.slice(0, 20));
}, 3000);
});
sock.on('close', function(data){
console.log('Closed ' + sock.remoteAddress + ' ' + sock.remotePort);
});
}).listen(port, host);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment