• Like

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Node.JS and WebSockets with Faye

  • 6,894 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
6,894
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
74
Comments
0
Likes
9

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Node.JS andWebSocketswithFaye
    Matjaž Lipuš
    @MatjazL
  • 2. Real-time web
    The real-time web is a set of technologies and practices which
    enable users to receive information as soon as it is published.
    http://en.wikipedia.org/wiki/Real-time_web
  • 3. Real-time web - Server
    Long, streaming connections
    Apache, IIS
    Node, nginx, Tornado, Thin, Netty
  • 4. Real-time web - Client
    Fast, small, simple API
    Long polling, streaming, websockets
    socket.IO, Faye
  • 5. NodeJS
    JavaScript bindings to system I/O
    Server-side JavaScript (Google’s V8)
    Most of Node is written in JavaScript
    Current v0.2.4
    more: http://nodejs.org
  • 6. NodeJS - nonblocking I/O
    (almost) nothing blocks
    Similar to EventMachine and Twisted
    without "run()", simply enters event loop, like browser
    No function should direct perform I/O
    Stream everything; never force the buffering of data
  • 7. NodeJS - nonblocking I/O
    puts("Enter your name: ");
    var name = gets();
    puts("Name: " + name);
    puts("Enter your name: ");
    gets(function (name) {
    puts("Name: " + name);
    });
  • 8. NodeJS - One process and thread
    Event loop
    events
    callbacks
    Multi processes
    web workers API
    multi-node module
  • 9. NodeJS - HTTP protocol
    Built for web
    Easy library and framework development
    http.createServer(function(req, res) {
    res.writeHead(200, {
    "Content-Type": "text/plain"
    });
    res.end("HelloWorld ");
    }).listen(8080);
  • 10. NodeJS - JavaScript
    Anonymous functions, closures
    Only one callback at a time
    I/O through DOM event callbacks
    Javascript === evented programming
  • 11. NodeJS - Modules
    CommonJS
    Built-in
    process, util, buffer
    fs, net, http
    Third part
    http://github.com/ry/node/wiki/modules
    npm package manager
  • 12. NodeJS - Addons
    Glue to C and C++ libraries
    extern"C"voidinit (Handle<Object> target)
    http://github.com/ry/node_postgres
  • 13. NodeJS - In development
    API changes
    Unstable modules (SSL)
    Short release cycles
  • 14. Faye
    Simple pub/sub messaging for the web
    Bayeux
    more: http://faye.jcoglan.com
  • 15. Faye- Concepts / patterns
    Deferrable
    Observable
    Extensible
    Timeouts
    Logging
    Set
  • 16. Faye - Classes
    Server
    Connection
    Client
    Transport
    HttpTransport
    LocalTransport - in process
    WebSocket
    XHR - long polling
    JSONP - callback polling
    Channel
    Subscription
  • 17. Faye - Adapters
    NodeAdapter
    RackAdapter
    var server = newFaye.NodeAdapter({
    mount:   "/",
     timeout: 60
    });
  • 18. Faye - Server
    var Faye   = require("faye"),
       server = newFaye.NodeAdapter();
    server.listen(8000);
    server.getClient().publish("/email/new",{
     text: "New email has arrived!",
    });
  • 19. Faye - Client
    var client = new
    Faye.Client("http://localhost:8000/bayeux");
    client.subscribe("/messages", function(message) {
     alert("Got a message: " + message.text);
    });
    client.publish("/messages", {
      text: "Can anyone hear me?"
    });
  • 20. Faye - Extensions
    varserverAuth = {
     incoming: function(message, callback) {
       if (message.channel === "/meta/subscribe") {
         checkAuth(message, function(authorized) {
           if (!authorized) {
             message.error = "Access denied";
           }
           callback(message);
         });
       } else {
         callback(message);
       }
     }
    };
    server.addExtension(serverAuth);
    server.removeExtension(serverAuth);
  • 21. Links
    http://nodejs.org
    http://faye.jcoglan.com
    http://howtonode.org
    http://s3.amazonaws.com/four.livejournal/20091117/jsconf.pdf
    http://nodejs.org/jsconf2010.pdf
    http://howtonode.org/step-of-conductor
  • 22. Contact
    Matjaž Lipuš
    @MatjazL