public
Last active

  • Download Gist
bayeux_load_server.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#!/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);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.