Skip to content

Instantly share code, notes, and snippets.

@nicokaiser
Created March 13, 2012 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicokaiser/2031620 to your computer and use it in GitHub Desktop.
Save nicokaiser/2031620 to your computer and use it in GitHub Desktop.
WebSocket.IO Leak Test
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