當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。