Created
March 13, 2012 21:09
-
-
Save nicokaiser/2031620 to your computer and use it in GitHub Desktop.
WebSocket.IO Leak Test
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 http = require('http') | |
, net = require('net') | |
, util = require('util') | |
, wsio = require('websocket.io'); | |
var server = http.createServer(function (req, res) { | |
res.writeHead(200, { 'Content-Type': 'text/html' }); | |
res.end('ok'); | |
}); | |
var ws = wsio.attach(server); | |
var i = 0; | |
ws.on('connection', function (client) { | |
var id = ++i; | |
console.log('Client %d connected', id); | |
client.send('ping!'); | |
client.on('message', function(data) { | |
client.send(data); | |
}); | |
client.on('error', function(err) { | |
console.error(err); | |
}); | |
client.on('close', function() { | |
console.log('Client %d disconnected', id); | |
}); | |
}); | |
server.listen(9000); | |
setInterval(function() { | |
util.log(ws.clientsCount + ' clients'); | |
util.log(JSON.stringify(process.memoryUsage())); | |
}, 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment