我正在使用此代码从源获取连续的无限数据流,对其进行处理,然后将处理后的无限流发送到连接到我的服务器的客户端。问题是龙卷风只支持一个 websocket 连接,但我想将数据转发到连接到我的服务器的所有客户端。如何支持多个客户端?
import tornado.httpserver
import tornado.websocket
import tornado.ioloop
import tornado.web
class WSHandler(tornado.websocket.WebSocketHandler):
def open(self):
print 'new connection'
self.write_message("Hello World")
def readData(self):
while True:
--continue generating data--
self.write_message(generated data)
def on_message(self, message):
print 'message received %s' % message
def on_close(self):
print 'connection closed'
application = tornado.web.Application([
(r'/ws', WSHandler),
])
if __name__ == "__main__":
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(8888)
tornado.ioloop.IOLoop.instance().start()