Exemplo n.º 1
0

@app.route('/')
def main():
    return render_template('sockjs.html')


class Socket(SockJSConnection):

    clients = set()

    def on_open(self, info):
        self.clients.add(self)
        print("Client connected")
        self.broadcast(self.clients, "Hello")

    def on_message(self, msg):
        self.broadcast(self.clients, msg)

    def on_close(self):
        self.clients.remove(self)
        print("Client disconnected")


tornado.sockets(SockJSRouter(Socket, '/sockjs').urls)


if __name__ == "__main__":
    app.debug = False
    tornado.run()