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


Python websocket.WebSocketClientFactory方法代码示例

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


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

示例1: __init__

# 需要导入模块: from autobahn.twisted import websocket [as 别名]
# 或者: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
def __init__(self, name, address, label, password, env_id=None, seed=None, fps=60,
                 start_timeout=None, observer=False, skip_network_calibration=False):
        self.name = name
        self.address = address
        self.label = label
        self.password = password
        self.env_id = env_id
        self.seed = None
        self.fps = fps
        self.start_timeout = start_timeout
        self.observer = observer
        self.skip_network_calibration = skip_network_calibration

        self.reward_buffer = reward_buffer.RewardBuffer(label=self.label)

        factory = websocket.WebSocketClientFactory('ws://'+address)
        factory.reward_buffer = self.reward_buffer
        factory.label = self.label
        self.rewarder_client = rewarder_client.RewarderClient()
        self.rewarder_client.factory = factory
        self.rewarder_client.onConnect(None) 
开发者ID:openai,项目名称:universe,代码行数:23,代码来源:test_semantics.py

示例2: pushImage

# 需要导入模块: from autobahn.twisted import websocket [as 别名]
# 或者: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
def pushImage(self):
        self.protocol.pushImage()


# Client is created for each test, connects and disconnects.
# class MyClientProtocol(WebSocketClientProtocol):

#    def onOpen(self):
#       self.sendMessage(u"Hello, world!".encode('utf8'))

#    def onMessage(self, payload, isBinary):
#       if isBinary:
#          print("Binary message received: {0} bytes".format(len(payload)))
#       else:
#          print("Text message received: {0}".format(payload.decode('utf8')))

# clientFactory = WebSocketClientFactory(u"ws://127.0.0.1:9090")
# clientFactory.protocol = MyClientProtocol

# -----------------------------------------------------------------------------
# Testing Taken from autobahn/test/__init__.py
# ----------------------------------------------------------------------------- 
开发者ID:Kitware,项目名称:wslink,代码行数:24,代码来源:testWSProtocol.py

示例3: connect_upstream

# 需要导入模块: from autobahn.twisted import websocket [as 别名]
# 或者: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
def connect_upstream(self, tries=1, max_attempts=7):
        if self._closed:
            logger.info("[RewardProxyServer] [%d] Attempted to connect upstream although client connection is already closed. Aborting",
                        self.id)
            return

        remote = getattr(self.factory, 'rewarder_address', 'localhost:15900')
        endpoint = endpoints.clientFromString(reactor, 'tcp:' + remote)
        client_factory = websocket.WebSocketClientFactory('ws://' + remote)
        headers = {'authorization': self._request.headers['authorization']}
        if self._request.headers.get('openai-observer'):
            headers['openai-observer'] = self._request.headers.get('openai-observer')
        client_factory.headers = headers
        client_factory.protocol = RewardServerClient
        client_factory.proxy_server = self
        client_factory.endpoint = endpoint

        logger.info("[RewardProxyServer] [%d] Connecting to upstream %s (try %d/%d)", self.id, remote, tries, max_attempts)

        def _connect_callback(client):
            logger.info('[RewardProxyServer] [%d] Upstream connection %s established', self.id, remote)
            self.client = client
            if self.factory.logfile_dir:
                self.begin_recording()

        def _connect_errback(reason):
            if tries < max_attempts:
                # Somewhat arbitrary exponential backoff: should be
                # pretty rare, and indicate that we're just starting
                # up.
                delay = 1.5 ** tries
                logger.info('[RewardProxyServer] [%d] Connection to %s failed: %s. Try %d/%d; going to retry in %fs', self.id, remote, reason, tries, max_attempts, delay)
                reactor.callLater(
                    delay, self.connect_upstream,
                    tries=tries+1, max_attempts=max_attempts)
            else:
                logger.error('[RewardProxyServer] [%d] Connection to %s failed: %s. Completed %d/%d atttempts; disconnecting.', self.id, remote, reason, tries, max_attempts)
                self.transport.loseConnection()

        endpoint.connect(client_factory).addCallbacks(_connect_callback, _connect_errback) 
开发者ID:openai,项目名称:universe,代码行数:42,代码来源:reward_proxy_server.py

示例4: connect_to_socket

# 需要导入模块: from autobahn.twisted import websocket [as 别名]
# 或者: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
def connect_to_socket(port, observers=None):
        if port is None:
            raise ValueError('port', port)
        
        api_server = token_ops.get_api_server()
        if api_server is not None:
            if api_server.startswith('https://'):
                api_server = api_server.replace('https://', 'wss://')
            if api_server.endswith('/'):
                api_server = api_server[:-1]
        
            url = api_server + ':' + str(port)
            
            logging.info('connect_to_socket')
            logging.info('Establishing socket connection:  %s' % url)
            
            factory = WebSocketClientFactory(url)
            factory.protocol = IQStreamer
            
            connectWS(factory)
            
            if observers is not None:
                publisher = StreamPublisher()
                for obs in observers:
                    publisher.register(obs)
            
            try:
                factory.reactor.run(installSignalHandlers=False)
            except error.ReactorAlreadyRunning:
                pass 
开发者ID:pcinat,项目名称:QuestradeAPI_PythonWrapper,代码行数:32,代码来源:IQStreamer.py

示例5: __init__

# 需要导入模块: from autobahn.twisted import websocket [as 别名]
# 或者: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
def __init__(self, RC, *args, **kwargs):
        websocket.WebSocketClientFactory.__init__(self, *args, **kwargs)
        self._RC = RC 
开发者ID:warner,项目名称:magic-wormhole,代码行数:5,代码来源:_rendezvous.py

示例6: buildProtocol

# 需要导入模块: from autobahn.twisted import websocket [as 别名]
# 或者: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
def buildProtocol(self, addr):
        proto = websocket.WebSocketClientFactory.buildProtocol(self, addr)
        proto._RC = self._RC
        # proto.wormhole_open = False
        return proto 
开发者ID:warner,项目名称:magic-wormhole,代码行数:7,代码来源:_rendezvous.py


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