本文整理汇总了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