Escolar Documentos
Profissional Documentos
Cultura Documentos
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
database
template httpClient auth S3Server
MySQL
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
- Asynchronous Requests
www.website.com
Picasa/Flickr
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
Q/A minute
Hack it now
http://www.slideshare.net/cristianAndreica/tornado
Thank YOU!