当前位置: 首页>>代码示例>>Python>>正文


Python threadedclient.WebSocketClient类代码示例

本文整理汇总了Python中ws4py.client.threadedclient.WebSocketClient的典型用法代码示例。如果您正苦于以下问题:Python WebSocketClient类的具体用法?Python WebSocketClient怎么用?Python WebSocketClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WebSocketClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: inner

    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)
开发者ID:fcwill,项目名称:python-fchat,代码行数:26,代码来源:fchat.py

示例2: __init__

 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 = {}
开发者ID:onepercentclub,项目名称:python-ddp,代码行数:7,代码来源:DDPClient.py

示例3: __init__

    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)
开发者ID:dkkline,项目名称:pychromecast,代码行数:7,代码来源:websocket.py

示例4: __init__

    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
开发者ID:ct2034,项目名称:robotino,代码行数:34,代码来源:msb_ws4py_client.py

示例5: __init__

    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
开发者ID:3Scan,项目名称:pyMeteor,代码行数:32,代码来源:pyDDP.py

示例6: connectDDP

    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!")
开发者ID:3Scan,项目名称:pyMeteor,代码行数:27,代码来源:pyDDP.py

示例7: __init__

    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()
开发者ID:Caltech-IPAC,项目名称:firefly,代码行数:29,代码来源:firefly_client.py

示例8: waitForEvents

 def waitForEvents(self):
     """
     Pause and do not exit.  Wait over events from the server.
     This is optional. You should not use this method in ipython notebook
     Event will get called anyway.
     """
     WebSocketClient.run_forever(self)
开发者ID:jonathansick-shadow,项目名称:firefly,代码行数:7,代码来源:FireflyClient.py

示例9: __init__

	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))
开发者ID:ruuk,项目名称:PushbulletTargets,代码行数:7,代码来源:__init__.py

示例10: __init__

 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
开发者ID:alumae,项目名称:kaldi-gstreamer-server,代码行数:25,代码来源:worker.py

示例11: __init__

    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
开发者ID:zeus911,项目名称:opsagent,代码行数:28,代码来源:manager.py

示例12: reconnect

 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)
开发者ID:LCAS,项目名称:rosduct,代码行数:8,代码来源:rosbridge_client.py

示例13: __init__

 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
开发者ID:fcwill,项目名称:python-fchat,代码行数:8,代码来源:fchat.py

示例14: __init__

 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."
开发者ID:hopkira,项目名称:k9-chess-angular,代码行数:8,代码来源:assistant.py

示例15: __init__

 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)
开发者ID:andrea689,项目名称:arduino-ciao-meteor-ddp-connector,代码行数:8,代码来源:DDPClient.py


注:本文中的ws4py.client.threadedclient.WebSocketClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。