Faye Bayeaux 프로토콜 Node.js를 위한 서버 혜성 프로토콜 ( Faye: Bayeaux protocol Comet server for Node.js )

Posted at 2010/02/10 09:52 // in Development/Ajaxian // by takeone

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.

James Coglan 루비/이벤트머신 혜성 서버 새로운 Bayeux 프로토콜안에 Node.js 서버로 제공되고있다. 이 프로젝트는 Faye 이고 당신은 GitHub의 코드에서 확인할수 있다.

On the client side:

클라이언트 코드

HTML:
  1.  
  2. <script type="text/javascript" src="/comet.js"></script>
  3.  
  4. <script type="text/javascript">
  5.     CometClient = new Faye.Client('/comet');
  6.     CometClient.connect();
  7. </script>
  8.  
JAVASCRIPT:
  1.  
  2.   CometClient.subscribe('/path/to/channel', function(message) {
  3.     // process received message object
  4.   });
  5.  
  6.   CometClient.publish('/some/other/channel', {foo: 'bar'});
  7.  

And the backend....

그리고 백엔드단

JAVASCRIPT:
  1.  
  2.   var http  = require('http')
  3.       faye  = require('./faye');
  4.  
  5.   var comet = new faye.NodeAdapter({mount: '/comet', timeout: 45});
  6.  
  7.   http.createServer(function(request, response) {
  8.     if (comet.call(request, response)) return;
  9.  
  10.     response.sendHeader(200, {'Content-Type': 'text/plain'});
  11.     response.sendBody('Hello, non-Comet request!');
  12.     response.finish();
  13.  
  14.   }).listen(9292);
  15.  

Nice!

좋았어

2010/02/10 09:52 2010/02/10 09:52

http://www.takeone.pe.kr/trackback/264