python Socket.IO client for sending broadcast messages to TornadIO2 server

前端 未结 3 1405
滥情空心
滥情空心 2020-12-04 17:15

I am building a realtime web application. I want to be able to send broadcast messages from the server-side implementation of my python application.

3条回答
  •  [愿得一人]
    2020-12-04 17:37

    I write here, because it's difficult write in comments section. You can view examples for tornadoio2 in examples directory where you can find implementation of chat, and:

    class ChatConnection(tornadio2.conn.SocketConnection):
        # Class level variable
        participants = set()
    
        def on_open(self, info):
            self.send("Welcome from the server.")
            self.participants.add(self)
    
        def on_message(self, message):
            # Pong message back
            for p in self.participants:
                p.send(message)
    

    As you can see they implemented participants as set ))

提交回复
热议问题