当前位置: 首页>>代码示例>>Python>>正文


Python WebSocketManager.broadcast方法代码示例

本文整理汇总了Python中ws4py.manager.WebSocketManager.broadcast方法的典型用法代码示例。如果您正苦于以下问题:Python WebSocketManager.broadcast方法的具体用法?Python WebSocketManager.broadcast怎么用?Python WebSocketManager.broadcast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ws4py.manager.WebSocketManager的用法示例。


在下文中一共展示了WebSocketManager.broadcast方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_broadcast

# 需要导入模块: from ws4py.manager import WebSocketManager [as 别名]
# 或者: from ws4py.manager.WebSocketManager import broadcast [as 别名]
    def test_broadcast(self, MockSelectPoller):
        m = WebSocketManager(poller=MockSelectPoller())

        ws = MagicMock()
        ws.terminated = False
        m.add(ws)

        m.broadcast(b'hello there')
        ws.send.assert_call_once_with(b'hello there')
开发者ID:17dakmue,项目名称:WebSocket-for-Python,代码行数:11,代码来源:test_manager.py

示例2: test_broadcast_failure_must_not_break_caller

# 需要导入模块: from ws4py.manager import WebSocketManager [as 别名]
# 或者: from ws4py.manager.WebSocketManager import broadcast [as 别名]
    def test_broadcast_failure_must_not_break_caller(self, MockSelectPoller):
        m = WebSocketManager(poller=MockSelectPoller())

        ws = MagicMock()
        ws.terminated = False
        ws.send.side_effect = RuntimeError
        m.add(ws)

        try:
                m.broadcast(b'hello there')
        except:
                self.fail("Broadcasting shouldn't have failed")
开发者ID:17dakmue,项目名称:WebSocket-for-Python,代码行数:14,代码来源:test_manager.py

示例3: WebSocketPlugin

# 需要导入模块: from ws4py.manager import WebSocketManager [as 别名]
# 或者: from ws4py.manager.WebSocketManager import broadcast [as 别名]
class WebSocketPlugin(plugins.SimplePlugin):
    def __init__(self, bus):
        plugins.SimplePlugin.__init__(self, bus)
        self.manager = WebSocketManager()

    def start(self):
        self.bus.log("Starting WebSocket processing")
        self.bus.subscribe('stop', self.cleanup)
        self.bus.subscribe('handle-websocket', self.handle)
        self.bus.subscribe('websocket-broadcast', self.broadcast)
        self.manager.start()

    def stop(self):
        self.bus.log("Terminating WebSocket processing")
        self.bus.unsubscribe('stop', self.cleanup)
        self.bus.unsubscribe('handle-websocket', self.handle)
        self.bus.unsubscribe('websocket-broadcast', self.broadcast)

    def handle(self, ws_handler, peer_addr):
        """
        Tracks the provided handler.

        :param ws_handler: websocket handler instance
        :param peer_addr: remote peer address for tracing purpose
        """
        self.manager.add(ws_handler)

    def cleanup(self):
        """
        Terminate all connections and clear the pool. Executed when the engine stops.
        """
        self.manager.close_all()
        self.manager.stop()
        self.manager.join()

    def broadcast(self, message, binary=False):
        """
        Broadcasts a message to all connected clients known to
        the server.

        :param message: a message suitable to pass to the send() method
          of the connected handler.
        :param binary: whether or not the message is a binary one
        """
        self.manager.broadcast(message, binary)
开发者ID:Lawouach,项目名称:WebSocket-for-Python,代码行数:47,代码来源:cherrypyserver.py


注:本文中的ws4py.manager.WebSocketManager.broadcast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。