Created
February 23, 2012 21:46
-
-
Save rottmanj/1895237 to your computer and use it in GitHub Desktop.
Simple node/faye remote server
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'), | |
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