Skip to content

Instantly share code, notes, and snippets.

@rottmanj
Created February 23, 2012 21:46
Show Gist options
  • Save rottmanj/1895237 to your computer and use it in GitHub Desktop.
Save rottmanj/1895237 to your computer and use it in GitHub Desktop.
Simple node/faye remote server
var http = require('http'),
faye = require('faye');
var bayeux = new faye.NodeAdapter({mount: '/bayeux', timeout: 20}),
port = process.argv[2] || '8000'
var server = require('http').createServer(function(req, res){
res.writeHead(200, {'Content-Type':'text/html'});
res.end();
});
bayeux.attach(server);
server.listen(Number(port));
bayeux.getClient().subscribe('/comment/*', function(message) {
console.log('[' + message.user + ']: ' + message.message);
});
bayeux.bind('subscribe', function(clientId, channel) {
console.log('[ SUBSCRIBE] ' + clientId + ' -> ' + channel);
});
bayeux.bind('unsubscribe', function(clientId, channel) {
console.log('[UNSUBSCRIBE] ' + clientId + ' -> ' + channel);
});
bayeux.bind('disconnect', function(clientId) {
console.log('[ DISCONNECT] ' + clientId);
});
console.log('Listening on ' + port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment