Getting started with tornado

Download tornado eBook

Remarks

Tornado is a Python web framework and asynchronous networking library, that uses non-blocking network I/O which allows it to scale to tens of thousands of open connections, making it ideal for long polling, WebSockets, and other applications that require a long-lived connection to each user.

Versions

Release Notes

Hello World

# hello_server.py
import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

    def make_app():
        return tornado.web.Application([ (r"/", MainHandler), ])  # URL Mapping

if __name__ == "__main__":
    app = make_app()
    app.listen(8888)    # Port Number
    tornado.ioloop.IOLoop.current().start()
 

This App is run by typing python3 hello_server.py or python hello_server.py depending on the version of Python being used.
When run locally the server can be accessed by going to 127.0.0.1:8888 from the browser.
The server will return "Hello World".
In make_app() function, the root / is mapped to MainHandler . This means that requests to the root IP 127.0.0.1:8888 will be mapped to the MainHandler function.

Installation or Setup

Python3 - sudo pip3 install tornado
Python2 - sudo pip install tornado

Packages which will are optional but recommended to install alongside Tornado :

Stats

29 Contributors: 2
Monday, September 12, 2016
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook