forked from edison12a/PyklaJan2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (31 loc) · 1017 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import tornado.ioloop
import tornado.web
import tornado.websocket
import tornado.wsgi
class GetHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
class HomeHandler(tornado.web.RequestHandler):
def get(self):
self.write("<h1 style='color: bl'>Welcome to our home page</h1>")
class EchoWebSocket(tornado.websocket.WebSocketHandler):
def open(self):
print("WebSocket opened")
def on_message(self, message):
self.write_message(u"You said: " + message)
def on_close(self):
print("WebSocket closed")
def check_origin(self, origin):
return True
def make_app():
"initializes the web server"
return tornado.web.Application([
(r"/", GetHandler),
(r"/home", HomeHandler),
(r"/websocket", EchoWebSocket)
])
if __name__ == "__main__":
webapp = make_app()
application = tornado.wsgi.WSGIContainer(webapp)
webapp.listen(22222)
tornado.ioloop.IOLoop.instance().start()