本文整理匯總了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)
示例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
# -----------------------------------------------------------------------------
示例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)
示例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
示例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
示例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