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


Python WebSocketManager.join方法代码示例

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


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

示例1: WSGIServer

# 需要导入模块: from ws4py.manager import WebSocketManager [as 别名]
# 或者: from ws4py.manager.WebSocketManager import join [as 别名]
class WSGIServer(_WSGIServer):
    def initialize_websockets_manager(self):
        """
        Call thos to start the underlying websockets
        manager. Make sure to call it once your server
        is created.
        """
        self.manager = WebSocketManager()
        self.manager.start()

    def shutdown_request(self, request):
        """
        The base class would close our socket
        if we didn't override it.
        """
        pass

    def link_websocket_to_server(self, ws):
        """
        Call this from your WSGI handler when a websocket
        has been created.
        """
        self.manager.add(ws)

    def server_close(self):
        """
        Properly initiate closing handshakes on
        all websockets when the WSGI server terminates.
        """
        if hasattr(self, 'manager'):
            self.manager.close_all()
            self.manager.stop()
            self.manager.join()
            delattr(self, 'manager')
        _WSGIServer.server_close(self)
开发者ID:Anderson-Juhasc,项目名称:bitex,代码行数:37,代码来源:wsgirefserver.py

示例2: WebSocketPlugin

# 需要导入模块: from ws4py.manager import WebSocketManager [as 别名]
# 或者: from ws4py.manager.WebSocketManager import join [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

示例3: run

# 需要导入模块: from ws4py.manager import WebSocketManager [as 别名]
# 或者: from ws4py.manager.WebSocketManager import join [as 别名]
def run(script_options):
    global logger
    level  = logging.DEBUG if script_options.verbose else logging.INFO
    logger = configure_logger(level = level)

    mgr = WebSocketManager()

    try:
        mgr.start()
        clients = []

        # Connect
        for connection_idx in range(script_options.concurrency):
            client = EchoClient(script_options.url, mgr,
                                script_options.ca, script_options.key, script_options.cert)
            client.connect()
            clients.append(client)

        logger.info("%d clients are connected" % (connection_idx + 1))

        # Send
        msg = getMessage(script_options)
        if msg:
            msg = json.write(msg)
            logger.info("Sending messages (num=%d):\n%s", script_options.num, msg)
            for client in clients:
                for _ in range(script_options.num):
                    client.send(msg)
                    time.sleep(SEND_INTERVAL)
            logger.info("Done sending")

        # Sleep before disconnecting
        logger.info("Sleeping for %d s before disconnecting",
                    script_options.interval)
        time.sleep(script_options.interval)

    except KeyboardInterrupt:
        logger.info("Interrupted by user")
    finally:
        logger.info("Disconnecting!")
        mgr.close_all(code    = 1000,
                      message = "Client is closing the connection")
        mgr.stop()
        mgr.join()
开发者ID:branan,项目名称:cpp-pcp-client,代码行数:46,代码来源:cthun_test.py

示例4: tempread

# 需要导入模块: from ws4py.manager import WebSocketManager [as 别名]
# 或者: from ws4py.manager.WebSocketManager import join [as 别名]
            gpio.pinMode(pin, gpio.OUTPUT)
            gpio.digitalWrite(pin,int(pins[pin]))

def tempread(pin):
    value = analog_read(pin)
    tempr = (value * 3.3)/4096*100
    return tempr

if __name__ == '__main__':
    import time

    try:
        m.start()
        client = EchoClient('ws://tairy.me:8888/ws')
        client.connect()

        sendmes = {"userid":userid}
        while True:
            for ws in m.websockets.itervalues():
                if not ws.terminated:
                    sendmes["data"] = {"temp":tempread(2)}
                    ws.send(json.JSONEncoder().encode(sendmes))
                    break
            else:
                break
            time.sleep(3)
    except KeyboardInterrupt:
        m.close_all()
        m.stop()
        m.join()
开发者ID:Tairy,项目名称:zaihuitou,代码行数:32,代码来源:client.py


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