Tuesday, February 9th, 2010
Faye: Bayeaux protocol Comet server for Node.js
James Coglan has ported a Ruby/EventMachine Comet server to offer a new Node.js server on the Bayeux protocol. The project is Faye and you can check out the code on GitHub.
On the client side:
-
-
CometClient.subscribe('/path/to/channel', function(message) {
-
// process received message object
-
});
-
-
CometClient.publish('/some/other/channel', {foo: 'bar'});
-
And the backend....
-
-
var http = require('http')
-
faye = require('./faye');
-
-
var comet = new faye.NodeAdapter({mount: '/comet', timeout: 45});
-
-
http.createServer(function(request, response) {
-
if (comet.call(request, response)) return;
-
-
response.sendHeader(200, {'Content-Type': 'text/plain'});
-
response.sendBody('Hello, non-Comet request!');
-
response.finish();
-
-
}).listen(9292);
-
Nice!












Leave a comment