Skip to content
Browse files

Added tornado python server

  • Loading branch information...
1 parent 0dff9a7 commit b8ca97db9f7a3c09af0ff87f8cd82b145d22b1de dvir volk committed Jun 14, 2012
Showing with 42 additions and 0 deletions.
  1. +42 −0 competition/wsdemo-tornado.py
View
42 competition/wsdemo-tornado.py
@@ -0,0 +1,42 @@
+import tornado.ioloop
+import tornado.options
+import tornado.web
+import tornado.websocket
+import tornado.httpserver
+import tornado.netutil
+import tornado.process
+
+class Application(tornado.web.Application):
+ def __init__(self):
+ handlers = [
+ (r"/", MyWebSocketHandler),
+ ]
+ tornado.web.Application.__init__(self, handlers)
+
+
+class MyWebSocketHandler(tornado.websocket.WebSocketHandler):
+
+ def allow_draft76(self):
+ # for iOS 5.0 Safari
+ return False
+
+ def open(self):
+ pass
+
+ def on_message(self, message):
+ self.write_message(message, binary=True)
+
+
+def main():
+
+ server = tornado.httpserver.HTTPServer(Application())
+ sockets = tornado.netutil.bind_sockets(8000)
+ job = tornado.process.fork_processes(None)
+ server.add_sockets(sockets)
+ tornado.ioloop.IOLoop.instance().start()
+
+
+
+if __name__ == "__main__":
+ main()
+

0 comments on commit b8ca97d

Please sign in to comment.
Something went wrong with that request. Please try again.