Created
February 15, 2015 13:54
-
-
Save elvinio/9c5eed9399f2beac6869 to your computer and use it in GitHub Desktop.
Node.js Socket Server
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
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