Skip to content

Instantly share code, notes, and snippets.

@ben-bradley
Last active August 29, 2015 14:01
Show Gist options
  • Save ben-bradley/ed07ec051d31b77c343d to your computer and use it in GitHub Desktop.
Save ben-bradley/ed07ec051d31b77c343d to your computer and use it in GitHub Desktop.
nodejs-tcp-server.js
var net = require('net');
var server = net.createServer();
server.on('connection', function(socket) {
console.log('connected!');
var start = Math.floor(new Date().getTime()/1000);
socket.readings = {};
socket.on('end', function() {
console.log('wrote: '+socket.bytesWritten);
console.log('read : '+socket.bytesRead);
});
socket.on('data', function(data) {
socket.readings[Math.floor(new Date().getTime()/1000)] = socket.bytesRead;
});
socket.on('error', function() {});
socket.on('close', function() {
console.log('start: '+start);
console.log('end : '+Math.floor(new Date().getTime()/1000));
console.log(socket.readings);
console.log('wrote: '+socket.bytesWritten);
console.log('read : '+socket.bytesRead);
});
});
server.listen(8124);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment