Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Tornado server #4

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions competition/wsdemo-tornado.py
Original file line number Diff line number Diff line change
@@ -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()