Tuesday, February 9th, 2010
Category: Comet
, Node
<
p
>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:
HTML:
-
-
<script type="text/javascript" src="/comet.js"></script>
-
-
<script type="text/javascript">//
<![CDATA[
-
CometClient = new Faye.Client('/comet');
-
CometClient.connect();
-
// ]]></script>
-
JAVASCRIPT:
-
-
CometClient.subscribe('/path/to/channel', function(message) {
-
// process received message object
-
});
-
-
CometClient.publish('/some/other/channel', {foo: 'bar'});
-
And the backend....
JAVASCRIPT:
-
-
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!
- Node.js
Node.js, often called simply "Node" in conversation, is a development platform built on top of Google's V8 JavaScript virtual...
- Ajax via Comet supports Atlas
Lightstreamer is a push engine that delivers Ajax capabilities using the Comet paradigm. A new demo shows its support for Atlas, the Microsoft Ajax...
- Hosting boosts Comet's website performance
High street retailer Comet has boosted the performance of its e-commerce websites, which generated a £70m profit last year,...
- Ajaxian
Ajaxian is a resource for software developers who work with Ajax, PHP, ASP.net, jQuery, Javascript, NodeJS, noSQL, FP and...
- Joyent PaaS may turn Web app world upside down
Has the Platform as a Service world changed forever? A new service coming from Joyent may give stalwarts like Google App Engine a run for their...
Leave a comment