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.

Like this presentation? Why not share!

Node.JS and WebSockets with Faye

on

  • 7,592 views

 

Statistics

Views

Total Views
7,592
Views on SlideShare
7,525
Embed Views
67

Actions

Likes
9
Downloads
72
Comments
0

3 Embeds 67

http://lanyrd.com 64
http://ld.siticom.mn 2
https://lanyrd.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Node.JS and WebSockets with Faye Node.JS and WebSockets with Faye Presentation Transcript

  • Node.JS andWebSocketswithFaye
    Matjaž Lipuš
    @MatjazL
  • 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
  • Real-time web - Server
    Long, streaming connections
    Apache, IIS
    Node, nginx, Tornado, Thin, Netty
  • Real-time web - Client
    Fast, small, simple API
    Long polling, streaming, websockets
    socket.IO, Faye
  • 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
  • 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
  • NodeJS - nonblocking I/O
    puts("Enter your name: ");
    var name = gets();
    puts("Name: " + name);
    puts("Enter your name: ");
    gets(function (name) {
    puts("Name: " + name);
    });
  • NodeJS - One process and thread
    Event loop
    events
    callbacks
    Multi processes
    web workers API
    multi-node module
  • 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);
  • NodeJS - JavaScript
    Anonymous functions, closures
    Only one callback at a time
    I/O through DOM event callbacks
    Javascript === evented programming
  • NodeJS - Modules
    CommonJS
    Built-in
    process, util, buffer
    fs, net, http
    Third part
    http://github.com/ry/node/wiki/modules
    npm package manager
  • NodeJS - Addons
    Glue to C and C++ libraries
    extern"C"voidinit (Handle<Object> target)
    http://github.com/ry/node_postgres
  • NodeJS - In development
    API changes
    Unstable modules (SSL)
    Short release cycles
  • Faye
    Simple pub/sub messaging for the web
    Bayeux
    more: http://faye.jcoglan.com
  • Faye- Concepts / patterns
    Deferrable
    Observable
    Extensible
    Timeouts
    Logging
    Set
  • Faye - Classes
    Server
    Connection
    Client
    Transport
    HttpTransport
    LocalTransport - in process
    WebSocket
    XHR - long polling
    JSONP - callback polling
    Channel
    Subscription
  • Faye - Adapters
    NodeAdapter
    RackAdapter
    var server = newFaye.NodeAdapter({
    mount:   "/",
     timeout: 60
    });
  • Faye - Server
    var Faye   = require("faye"),
       server = newFaye.NodeAdapter();
    server.listen(8000);
    server.getClient().publish("/email/new",{
     text: "New email has arrived!",
    });
  • 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?"
    });
  • 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);
  • 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
  • Contact
    Matjaž Lipuš
    @MatjazL