Simple Tornado Web Server with Hello, World Message

  • Share this:

Code introduction


This code defines a simple Tornado web server that listens on port 8888 and returns a 'Hello, world' message. It uses the `RequestHandler` class from Tornado to handle HTTP requests, as well as the `Application` and `IOLoop` classes to set up and start the server.


Technology Stack : Tornado

Code Type : Tornado Web Server

Code Difficulty : Intermediate


                
                    
import tornado.ioloop
import tornado.web

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

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

    def start_server():
        app = make_app()
        app.listen(8888)
        tornado.ioloop.IOLoop.current().start()

    start_server()                
              
Tags: