tornado - How to send data to all clients? -


i have simple server:

# -*- coding: utf-8 -*-  import os import logging import tornado.httpserver import tornado.ioloop import tornado.options   class wshandler(tornado.websocket.websockethandler):      def check_origin(self, origin):         return true      def open(self):         print 'connection opened'      def on_message(self, message):         self.write_message("echo: " + message)         print 'received:', message      def on_close(self):         print 'connection closed'   class mainhandler(tornado.web.requesthandler):      def get(self):         self.write('ok')   url_patterns = [     (r'/ws', wshandler),     (r'/update', mainhandler), ]  application = tornado.web.application(     url_patterns,     debug=false )  if __name__ == "__main__":     application.listen(9991)     tornado.ioloop.ioloop.instance().start() 

and want send data connected clients via websocket when call "/update" browser. how it?

clients = []  class wshandler(tornado.websocket.websockethandler):     def open(self):         clients.append(self)         print 'connection opened'      def on_close(self):         clients.remove(self)         print 'connection closed'   class mainhandler(tornado.web.requesthandler):      def get(self):         client in clients:              client.write_message('ok')         self.write('ok') 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -