# 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.