Skip to content

Instantly share code, notes, and snippets.

@mgunneras
Created July 23, 2010 17:33
Show Gist options
  • Save mgunneras/487760 to your computer and use it in GitHub Desktop.
Save mgunneras/487760 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var http = require('http'),
faye = require('./faye-node');
var received = 0,
sent = 0;
function getTimestamp () {
return(new Date());
}
var bayeux = new faye.NodeAdapter({
mount: '/faye',
timeout: 50
});
var server = http.createServer(function(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end();
});
var log_ext = {
incoming: function(message, callback) {
if(message.channel == '/chat/demo') {
received++;
}
callback(message);
},
outgoing: function(message, callback) {
if(message.channel == '/chat/demo') {
sent++;
}
callback(message);
}
};
setInterval(function() {
var c_count = bayeux._server.clientIds().length;
console.log(getTimestamp() + ' CONNECTED CLIENTS: '+c_count+' RECEIVED: '+received+' SENT: '+sent);
}, 3000);
bayeux.addExtension(log_ext);
bayeux.attach(server);
server.listen(80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment