Your SlideShare is downloading. ×
0
×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Node.JS and WebSockets with Faye

7,145

Published on

Published in: Technology
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
7,145
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
81
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 and WebSockets with Faye 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 - non blocking 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 - non blocking 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("Hello Worldn"); }).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" void init (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 = new Faye.NodeAdapter({ mount: "/", timeout: 60 });
  • 18. Faye - Server var Faye = require("faye"), server = new Faye.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 var serverAuth = { 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

×