import tornado.ioloop
import tornado.web
import tornado.websocket

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

class WebsocketHandler(tornado.websocket.WebSocketHandler):
    def open(self):
        print("Opened...")

    def on_message(self, message):
        print("Got a message: " + message)
        self.write_message(u"You wrote: {0}".format(message))

    def on_close(self):
        print("Closed...")

if __name__ == "__main__":
    print("Start of the server...")
    application = tornado.web.Application([
        (r"/", MainHandler),
        (r"/socket", WebsocketHandler),
    ])
    print("Starting to listen on port 8888")
    application.listen(8888)
    tornado.ioloop.IOLoop.current().start()
