Last active
August 29, 2015 14:01
-
-
Save ben-bradley/ed07ec051d31b77c343d to your computer and use it in GitHub Desktop.
nodejs-tcp-server.js
This file contains 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
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