Tornado
-
Upload
cristian-andreica -
Category
Technology
-
view
3.844 -
download
2
description
Transcript of Tornado
![Page 1: Tornado](https://reader036.fdocuments.in/reader036/viewer/2022082700/54bf77954a795940398b4593/html5/thumbnails/1.jpg)
Real Time Web Server
![Page 2: Tornado](https://reader036.fdocuments.in/reader036/viewer/2022082700/54bf77954a795940398b4593/html5/thumbnails/2.jpg)
• Real Time, so what?• Tornado – The baby that comes with it• 1000s simultaneously active connections
![Page 3: Tornado](https://reader036.fdocuments.in/reader036/viewer/2022082700/54bf77954a795940398b4593/html5/thumbnails/3.jpg)
• 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
![Page 4: Tornado](https://reader036.fdocuments.in/reader036/viewer/2022082700/54bf77954a795940398b4593/html5/thumbnails/4.jpg)
•FriendFeed
•core
web•XHTML
•JSON
•URL encoding/decoding
escape•MySQL
database
•Python-based templating language
template
•Non-blocking http client
•Works with web module
httpClient
•Google OpenID/OAuth, Yahoo BBAuth
•Facebook Platform
• Twitter OAuth
auth
•Amazon S3
S3Server
- Module List
![Page 5: Tornado](https://reader036.fdocuments.in/reader036/viewer/2022082700/54bf77954a795940398b4593/html5/thumbnails/5.jpg)
• 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 argumentsclass 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
![Page 6: Tornado](https://reader036.fdocuments.in/reader036/viewer/2022082700/54bf77954a795940398b4593/html5/thumbnails/6.jpg)
• HTML Templates<html> <head>
<title>{{ title }}</title> </head> <body>
<ul> {% for item in items %} <li>{{ escape(item) }}</li> {% end %} </ul>
</body> </html>
• Template Handlerclass MainHandler(tornado.web.RequestHandler):
def get(self): Items = ["Item 1", "Item 2", "Item 3"] self.render("template.html", title="My title", items=items)
- Code Snippets
![Page 7: Tornado](https://reader036.fdocuments.in/reader036/viewer/2022082700/54bf77954a795940398b4593/html5/thumbnails/7.jpg)
Web Page
<short python code here…>
- UI Modules
Widget- HTML, CSS- JavaScript- MySQL
myModule.py
Blog Post 1
Widget
Blog Post 2
Widget
![Page 8: Tornado](https://reader036.fdocuments.in/reader036/viewer/2022082700/54bf77954a795940398b4593/html5/thumbnails/8.jpg)
- Asynchronous Requests
www.website.com Picasa/Flickr1. Fetch data
2. Response (callback)
Synchronous Requests• immediate server response• cannot later-update the client
Asynchronous Requests• immediate server response• allows for 3rd party services• push technologies
![Page 9: Tornado](https://reader036.fdocuments.in/reader036/viewer/2022082700/54bf77954a795940398b4593/html5/thumbnails/9.jpg)
- References
Tornado - http://www.tornadoweb.org/Epoll man page - http://linux.die.net/man/4/epollLong Pooling - http://en.wikipedia.org/wiki/Push_technologyCSRF - http://en.wikipedia.org/wiki/Cross-site_request_forgery
Hack it now…Q/A minute
Non-blocking
Asynchronous
Long-polling
modular
Web Server
Signed Cookies
CSRF Protection
![Page 10: Tornado](https://reader036.fdocuments.in/reader036/viewer/2022082700/54bf77954a795940398b4593/html5/thumbnails/10.jpg)
Thank YOU!
Cristian Andreica331 CB
[email protected] : @acristian
http://www.slideshare.net/cristianAndreica/tornado