本文整理汇总了Python中ws4py.client.WebSocketBaseClient.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python WebSocketBaseClient.__init__方法的具体用法?Python WebSocketBaseClient.__init__怎么用?Python WebSocketBaseClient.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ws4py.client.WebSocketBaseClient
的用法示例。
在下文中一共展示了WebSocketBaseClient.__init__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def __init__(self, url, protocols=None, extensions=None,
io_loop=None, ssl_options=None, headers=None):
"""
.. code-block:: python
from tornado import ioloop
class MyClient(TornadoWebSocketClient):
def opened(self):
for i in range(0, 200, 25):
self.send("*" * i)
def received_message(self, m):
print((m, len(str(m))))
def closed(self, code, reason=None):
ioloop.IOLoop.instance().stop()
ws = MyClient('ws://localhost:9000/echo', protocols=['http-only', 'chat'])
ws.connect()
ioloop.IOLoop.instance().start()
"""
WebSocketBaseClient.__init__(self, url, protocols, extensions,
ssl_options=ssl_options, headers=headers)
if self.scheme == "wss":
self.sock = ssl.wrap_socket(self.sock, do_handshake_on_connect=False, **self.ssl_options)
self.io = iostream.SSLIOStream(self.sock, io_loop, ssl_options=self.ssl_options)
else:
self.io = iostream.IOStream(self.sock, io_loop)
self.io_loop = io_loop
示例2: __init__
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def __init__(self, currency, apiKey, apiSecret):
currencies = [currency]
url = 'ws://websocket.mtgox.com/mtgox?Currency=%s' % (",".join(currencies))
WebSocketBaseClient.__init__(self, url)
self.__nonce = None
self.__apiKey = apiKey
self.__apiSecret = apiSecret
示例3: __init__
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def __init__(self, url, protocols=None, extensions=None, heartbeat_freq=None,
ssl_options=None, headers=None):
"""
.. code-block:: python
from ws4py.client.threadedclient import WebSocketClient
class EchoClient(WebSocketClient):
def opened(self):
for i in range(0, 200, 25):
self.send("*" * i)
def closed(self, code, reason):
print(("Closed down", code, reason))
def received_message(self, m):
print("=> %d %s" % (len(m), str(m)))
try:
ws = EchoClient('ws://localhost:9000/echo', protocols=['http-only', 'chat'])
ws.connect()
except KeyboardInterrupt:
ws.close()
"""
WebSocketBaseClient.__init__(self, url, protocols, extensions, heartbeat_freq,
ssl_options, headers=headers)
self._th = threading.Thread(target=self.run, name='WebSocketClient')
self._th.daemon = True
示例4: reconnect
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def reconnect(self):
# Instead of trying to reconnect in a retry loop with backoff, run an API call that will do the same
# and block while it retries.
time.sleep(1)
dxpy.describe(self.job_id)
WebSocketBaseClient.__init__(self, self.url, protocols=None, extensions=None)
self.connect()
示例5: __init__
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def __init__(self, url, protocols=None, extensions=None, ssl_options=None):
"""
WebSocket client that executes the
:meth:`run() <ws4py.websocket.WebSocket.run>` into a gevent greenlet.
.. code-block:: python
ws = WebSocketClient('ws://localhost:9000/echo', protocols=['http-only', 'chat'])
ws.connect()
ws.send("Hello world")
def incoming():
while True:
m = ws.receive()
if m is not None:
print str(m)
else:
break
def outgoing():
for i in range(0, 40, 5):
ws.send("*" * i)
greenlets = [
gevent.spawn(incoming),
gevent.spawn(outgoing),
]
gevent.joinall(greenlets)
"""
WebSocketBaseClient.__init__(self, url, protocols, extensions, ssl_options=ssl_options)
self._th = Greenlet(self.run)
self.messages = Queue()
"""
示例6: __init__
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def __init__(self, url, protocols=None, extensions=None, io_loop=None):
WebSocketBaseClient.__init__(self, url, protocols, extensions)
if self.scheme == "wss":
self.sock = ssl.wrap_socket(self.sock, do_handshake_on_connect=False)
self.io = iostream.SSLIOStream(self.sock, io_loop)
else:
self.io = iostream.IOStream(self.sock, io_loop)
self.sender = self.io.write
self.io_loop = io_loop
示例7: __init__
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def __init__(self, url, protocols=None, extensions=None, io_loop=None,custom_headers=[]):
WebSocketBaseClient.__init__(self, url, protocols, extensions, custom_headers)
parts = urlsplit(self.url)
if parts.scheme == "wss":
self.sock = ssl.wrap_socket(self.sock,
do_handshake_on_connect=False)
self.io = iostream.SSLIOStream(self.sock, io_loop)
else:
self.io = iostream.IOStream(self.sock, io_loop)
self.sender = self.io.write
self.io_loop = io_loop
示例8: __init__
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def __init__(self, url, sock=None, protocols=None, version='8'):
WebSocketBaseClient.__init__(self, url, protocols=protocols, version=version)
if not sock:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
sock.settimeout(3)
self.sock = sock
self.running = True
self._lock = threading.Lock()
self._th = threading.Thread(target=self._receive)
示例9: __init__
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def __init__(self, url, protocols=None, extensions=None, heartbeat_freq=None,
ssl_options=None, headers=None):
WebSocketBaseClient.__init__(self, url, protocols, extensions, heartbeat_freq,
ssl_options, headers=headers)
self.callbacks = {}
self._connected = False
# create an unique ID
self._id = WebSocketClient._instance_count
WebSocketClient._instance_count += 1
示例10: __init__
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def __init__(self, job_id, input_params={}, msg_output_format="{job} {level} {msg}", msg_callback=None,
print_job_info=True):
self.seen_jobs = {}
self.input_params = input_params
self.msg_output_format = msg_output_format
self.msg_callback = msg_callback
self.print_job_info = print_job_info
self.closed_code, self.closed_reason = None, None
ws_proto = 'wss' if dxpy.APISERVER_PROTOCOL == 'https' else 'ws'
url = "{protocol}://{host}:{port}/{job_id}/streamLog/websocket".format(protocol=ws_proto,
host=dxpy.APISERVER_HOST,
port=dxpy.APISERVER_PORT,
job_id=job_id)
WebSocketBaseClient.__init__(self, url, protocols=None, extensions=None)
示例11: __init__
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def __init__(self, url, protocols=None, extensions=None, heartbeat_freq=None,
ssl_options=None, headers=None):
WebSocketBaseClient.__init__(self, url, protocols, extensions, heartbeat_freq,
ssl_options, headers=headers)
self.callbacks = {}
self._connected = False
self._local = False
self._version = ""
self._fd_notifier = None
# create an unique ID
self._id = WebSocketClient._instance_count
WebSocketClient._instance_count += 1
# set a default timeout of 10 seconds
# for connecting to a server
socket.setdefaulttimeout(10)
示例12: reconnect
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def reconnect(self):
"""
Reconnects to the server.
"""
WebSocketBaseClient.__init__(self,
self.url,
self.protocols,
self.extensions,
self.heartbeat_freq,
self.ssl_options,
self.extra_headers)
if self._local:
# check the local host address is still valid
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.bind((self.host, 0))
self.connect()
示例13: __init__
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def __init__(self, url, protocols=None, extensions=None,
heartbeat_freq=None, ssl_options=None, headers=None, instance_id=None):
WebSocketBaseClient.__init__(self, url,
protocols,
extensions,
heartbeat_freq,
ssl_options,
headers)
self.callbacks = {}
self._connected = False
self._local = False
self._cloud = False
self._version = ""
self._fd_notifier = None
self._heartbeat_timer = None
self._tunnel = None
self._instance_id = instance_id
# create an unique ID
self._id = WebSocketClient._instance_count
WebSocketClient._instance_count += 1
示例14: __init__
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def __init__(self, url, mgr, ca_certs = None, keyfile = None, certfile = None):
self._mgr = mgr
WebSocketBaseClient.__init__(self, url, ssl_options = {
"ca_certs" : ca_certs,
"keyfile" : keyfile,
"certfile" : certfile })
示例15: __init__
# 需要导入模块: from ws4py.client import WebSocketBaseClient [as 别名]
# 或者: from ws4py.client.WebSocketBaseClient import __init__ [as 别名]
def __init__(self, url, protocols=None, extensions=None):
WebSocketBaseClient.__init__(self, url, protocols, extensions)
self._th = threading.Thread(target=self.run, name='WebSocketClient')
self._th.daemon = True