A simple demo for tornado web socket

Python Code

images/tornado_websocket_python.png

JS Code

images/tornado_websocket_js.png

Subclass WebSocketHandler to create a basic WebSocket handler.

Override on_message to handle incoming messages, and use write_message to send messages to the client. You can also override open and on_close to handle opened and closed connections.

The only communication methods available to you are write_message(), ping(), and close(). Likewise, your request handler class should implement open() method rather than get() or post().

参考: tornado.websocket — Bidirectional communication to the browser