更新时间:2022-06-19 07:04:36
在 WebsocketHandler 之外使用 connections = set()
并在打开连接时使用 connections.add(self)
.不要忘记在关闭时使用 connections.remove(self)
删除它们.
Use connections = set()
outside the WebsocketHandler and add every client on opening a connection with connections.add(self)
. Do not forget to remove them on closing with connections.remove(self)
.
现在,您可以通过以下方式从 websocket 线程中访问 write_message
:[client.write_message('#your_message') for client in connections]
Now, you are able to access write_message
out of the websocket thread through: [client.write_message('#your_message') for client in connections]