Skip to content

Instantly share code, notes, and snippets.

@danielrobertson
Created November 15, 2015 20:01
Show Gist options
  • Select an option

  • Save danielrobertson/79eb7d99779bd1ecefef to your computer and use it in GitHub Desktop.

Select an option

Save danielrobertson/79eb7d99779bd1ecefef to your computer and use it in GitHub Desktop.
A TCP server that listens on the port given in command line arguments and writes the timestamp of connection to the connection
var net = require('net');
var port = process.argv[2];
var strftime = require('strftime');
var server = net.createServer(function (socket) {
var timestamp = strftime('%F %H:%M', new Date());
console.log(timestamp);
socket.write(timestamp);
socket.end();
});
server.listen(port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment