本文整理汇总了Python中ws4py.client.threadedclient.WebSocketClient.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python WebSocketClient.__init__方法的具体用法?Python WebSocketClient.__init__怎么用?Python WebSocketClient.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ws4py.client.threadedclient.WebSocketClient
的用法示例。
在下文中一共展示了WebSocketClient.__init__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def __init__(self, url, config, statesworker):
# init WS
WebSocketClient.__init__(self, url)
# variables
self.__config = config
self.__connected = False
self.__run = True
# recv sync
self.recv_event_e.set()
# actions map
self.__actions = {
codes.APP_NOT_EXIST : self.__act_retry_hs,
codes.AGENT_UPDATE : self.__act_update,
codes.RECIPE_DATA : self.__act_recipe,
codes.WAIT_DATA : self.__act_wait,
}
# init
self.__error_dir = self.__init_dir()
self.__error_proc = self.__mount_proc()
self.__update_ud()
self.__config['init'] = self.__get_id()
# states worker
self.__states_worker = statesworker
示例2: __init__
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def __init__(self, url, debugPrint=False, printDDP=False, raiseDDPErrors=False, printDDPErrors=True, attemptReconnect=True):
# Call the ws init functions
self.urlArg = url
WebSocketClient.__init__(self, url)
self._dbPrint = Printer(debugPrint=debugPrint)
self._printDDPError = Printer(debugPrint=printDDPErrors)
self._printDDP = Printer(debugPrint=printDDP)
# Record the outstanding method calls to link wrt requests
self.requestsToTrack = []
self.requestReplies = {}
self.subNameToID = {}
# Place to collect collections
self.collections = CollectionCollection()
# Store the flags for what to do in various scenarios
self.debugPrint = debugPrint
self.raiseDDPErrors = raiseDDPErrors
self.printDDP = printDDP
self.printDDPErrors = printDDPErrors
self.attemptReconnect = attemptReconnect
self.closeCallbacks = []
self.reconnectCallbacks = []
# Set the connected flag to False
self.DDP_Connected = False
# Flag to see if we requested a close connection
self.closeRequested = False
示例3: connectDDP
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def connectDDP(self, timeout=3, isReconnect=False):
if isReconnect:
self._dbPrint("Attempting reconnect with timeout: %i seconds. . ." % timeout)
self.close_connection() # try to free up some OS resources
time.sleep(timeout)
WebSocketClient.__init__(self, self.urlArg)
else:
self._dbPrint("Starting DDP connection. . .")
try:
self._attemptConnection()
# except (DDPError, ConnectionRefusedError) as e:
except Exception as e:
self._dbPrint("ddpClient._attemptConnection() raised an exception:")
print(e)
timeoutExponent = 1.2
if not self.attemptReconnect:
raise e
self.connectDDP(isReconnect=True, timeout=timeout * timeoutExponent)
else:
if isReconnect:
self._dbPrint("Reconnect successful!")
[cb() for cb in self.reconnectCallbacks]
self.run_forever()
else:
self._dbPrint("DDP connection established!")
示例4: __init__
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def __init__(self, host=_my_localhost, channel=None):
"""initialize a 'FireflyClient' object and build websocket.
Parameters
----------
host : str
Firefly host.
channel : str
WebSocket channel id.
"""
if host.startswith('http://'):
host = host[7:]
self.this_host = host
url = 'ws://%s/firefly/sticky/firefly/events' % host # web socket url
if channel:
url += '?channelID=%s' % channel
WebSocketClient.__init__(self, url)
self.url_root = 'http://' + host + self._fftools_cmd
self.url_bw = 'http://' + self.this_host + '/firefly/firefly.html;wsch='
self.listeners = {}
self.channel = channel
self.session = requests.Session()
# print 'websocket url:%s' % url
self.connect()
示例5: __init__
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def __init__(self, url, debug=False):
WebSocketClient.__init__(self, url)
EventEmitter.__init__(self)
self.debug = debug
self._session = None
self._uniq_id = 0
self._callbacks = {}
示例6: inner
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def inner(self):
while True:
self.logger.info("Connecting ...")
try:
self.setup()
self.connect()
func(self)
except KeyboardInterrupt:
self.close()
return
except WebSocketException as e:
self.logger.exception("WebSocketException")
except ConnectionError as e:
self.logger.error("Could not connect to server!")
except Exception:
self.logger.exception("Exception")
finally:
self.terminate_outgoing_thread()
self.logger.info("Trying to reconnect in %d seconds (%d attempt) ..." % (self.reconnect_delay, self.reconnect_attempt))
time.sleep(self.reconnect_delay)
if self.reconnect_delay < 120:
self.reconnect_delay *= 2
self.reconnect_attempt += 1
WebSocketClient.__init__(self, self.url)
示例7: __init__
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def __init__(self, uri, decoder_pipeline, post_processor, full_post_processor=None):
self.uri = uri
self.decoder_pipeline = decoder_pipeline
self.post_processor = post_processor
self.full_post_processor = full_post_processor
WebSocketClient.__init__(self, url=uri, heartbeat_freq=10)
self.pipeline_initialized = False
self.partial_transcript = ""
if USE_NNET2:
self.decoder_pipeline.set_result_handler(self._on_result)
self.decoder_pipeline.set_full_result_handler(self._on_full_result)
self.decoder_pipeline.set_error_handler(self._on_error)
else:
self.decoder_pipeline.set_word_handler(self._on_word)
self.decoder_pipeline.set_error_handler(self._on_error)
self.decoder_pipeline.set_eos_handler(self._on_eos)
self.state = self.STATE_CREATED
self.last_decoder_message = time.time()
self.request_id = "<undefined>"
self.timeout_decoder = 5
self.num_segments = 0
self.last_partial_result = ""
self.post_processor_lock = threading.Lock()
self.processing_condition = threading.Condition()
self.num_processing_threads = 0
示例8: __init__
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def __init__(self,token,most_recent=0,most_recent_callback=None):
self.mostRecent = most_recent
self.mostRecentUpdated = most_recent_callback or self.mostRecentUpdated
self.lastPing = time.time()
self.client = Client(token)
self.devices = {}
WebSocketClient.__init__(self,STREAM_BASE_URL.format(token))
示例9: __init__
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def __init__(self, url, supported_protocols):
WebSocketClient.__init__(self, url)
self.supported_protocols = supported_protocols
self.logger = logging.getLogger(__name__)
self.handlers = {}
self._weakref = weakref.ref(self)
示例10: __init__
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def __init__(self, url, defaultCallback):
self.connected = False
# check ws4py version
env = pkg_resources.Environment()
v = env['ws4py'][0].version.split(".")
if (int(v[0]) * 100 + int(v[1]) * 10 + int(v[2])) < 35:
raise RuntimeError("please use ws4py version 0.3.5 or higher")
self.conUUid = uuid.uuid1() # make uuid for connection
self.conUrl = (
url +
"/websocket/data/" +
str(self.conUUid.clock_seq_hi_variant) +
"/" +
str(self.conUUid) +
"/websocket"
)
self.defaultCallback = defaultCallback
self.functionCallbacks = {}
logging.info("initialized " + self.conUrl)
try:
WebSocketClient.__init__(self, self.conUrl)
self.connect()
self.connected = True
logging.info("connected: " + str(self.connected))
threading.Thread(target=self.run_forever).start()
except KeyboardInterrupt:
self.disconnect()
logging.error("KeyboardInterrupt")
except Exception as e:
self.disconnect()
raise e
示例11: __init__
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def __init__(self):
ws_url = 'wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize'
self.listening = False
try:
WebSocketClient.__init__(self, ws_url,
headers=[("X-Watson-Authorization-Token",auth_token)])
self.connect()
except: print "Failed to open WebSocket."
示例12: __init__
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def __init__(self, url, account, password, character, client_name="Python FChat Library"):
WebSocketClient.__init__(self, url)
self.account = account
self.password = password
self.character = character
self.client_name = client_name
self.reconnect_delay = 1
self.reconnect_attempt = 0
示例13: reconnect
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def reconnect(self):
WebSocketClient.__init__(self, self.urlstring)
self._connected = False
self.connect()
self.client_thread = threading.Thread(target=self.run_forever)
self.client_thread.start()
while not self._connected:
time.sleep(0.1)
示例14: __init__
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def __init__(self, url, debug=False):
self.debug = debug
# by default socket connections don't timeout. this causes issues
# where reconnects can get stuck
# TODO: make this configurable?
socket.setdefaulttimeout(10)
WebSocketClient.__init__(self, url)
EventEmitter.__init__(self)
示例15: __init__
# 需要导入模块: from ws4py.client.threadedclient import WebSocketClient [as 别名]
# 或者: from ws4py.client.threadedclient.WebSocketClient import __init__ [as 别名]
def __init__(self, webSocketDebuggerUrl, onload=None):
WebSocketClient.__init__(self, webSocketDebuggerUrl)
self.onload = onload
self.pendingCallbacks = {}
self.freeIds = []
self.connect()