Você está na página 1de 10

Real Time Web Server

Real Time, so what? Tornado The baby that comes with it 1000s simultaneously active connections

Open-source (Apache 2.0 License) Nginx Non-blocking web server Epoll (callbacks on the kernel file structure) Push vs Pull (long polling) Real-time web services

- Module List

web
escape

FriendFeed core XHTML JSON URL encoding/decoding

database
template httpClient auth S3Server

MySQL

Python-based templating language

Non-blocking http client Works with web module Google OpenID/OAuth, Yahoo BBAuth Facebook Platform Twitter OAuth Amazon S3

- Code Snippets
URL Mapping (get + post)
class MainHandler(tornado.web.RequestHandler): def get(self): self.write("You requested the main page") class StoryHandler(tornado.web.RequestHandler): def get(self, story_id): self.write("You requested the story " + story_id) application = tornado.web.Application([ (r"/", MainHandler), (r"/story/([0-9]+)", StoryHandler), ])

Post arguments
class MainHandler(tornado.web.RequestHandler): def get(self): self.write('<html><body><form action="/" method="post">' '<input type="text" name="message">' '<input type="submit" value="Submit">' '</form></body></html>') def post(self): self.set_header("Content-Type", "text/plain") self.write("You wrote " + self.get_argument("message"))

HTTPRequest

- Code Snippets
HTML Templates
<html> <head> <title>{{ title }}</title> </head> <body> <ul> {% for item in items %} <li>{{ escape(item) }}</li> {% end %} </ul> </body> </html>

Template Handler
class MainHandler(tornado.web.RequestHandler): def get(self): Items = ["Item 1", "Item 2", "Item 3"] self.render("template.html", title="My title", items=items)

- UI Modules

Blog Post 1 myModule.py

<short python code here>

Blog Post 2 Web Page

- Asynchronous Requests

www.website.com

1. Fetch data 2. Response (callback)

Picasa/Flickr

Synchronous Requests immediate server response cannot later-update the client

Asynchronous Requests immediate server response allows for 3rd party services push technologies

- References
CSRF Protection

Non-blocking

Long-polling modular

Web Server

Asynchronous

Signed Cookies

Tornado Epoll man page Long Pooling CSRF

http://www.tornadoweb.org/ http://linux.die.net/man/4/epoll http://en.wikipedia.org/wiki/Push_technology http://en.wikipedia.org/wiki/Cross-site_request_forgery

Q/A minute

Hack it now

Cristian Andreica 331 CB cristian.andreica@gmail.com : @acristian

http://www.slideshare.net/cristianAndreica/tornado

Thank YOU!

Você também pode gostar