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
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?"
});