Skip to content

Instantly share code, notes, and snippets.

@subzey
Created August 4, 2012 22:58
Show Gist options
  • Save subzey/3260444 to your computer and use it in GitHub Desktop.
Save subzey/3260444 to your computer and use it in GitHub Desktop.
simple node tcp server
var PORT = 23; // telnet
var tcpServer = require("net").createServer();
tcpServer.on('connection', function(socket){
var clientAddress = socket.remoteAddress + ':' + socket.remotePort;
console.log('%s connected', clientAddress);
socket.on('data', function(buffer){
console.log('%s sent %s byte(s)', clientAddress, buffer.length);
});
socket.on('end', function(){
console.log('%s disconnected', clientAddress);
});
});
tcpServer.listen(PORT, function(){
console.log('Port %s successfully opened, awaiting connections...', PORT);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment