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


Python zeroconf.ServiceBrowser方法代码示例

本文整理汇总了Python中zeroconf.ServiceBrowser方法的典型用法代码示例。如果您正苦于以下问题:Python zeroconf.ServiceBrowser方法的具体用法?Python zeroconf.ServiceBrowser怎么用?Python zeroconf.ServiceBrowser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zeroconf的用法示例。


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

示例1: run

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def run(self, ttl=None):
        if self.host:
            self.zeroconf = zeroconf.Zeroconf(interfaces=[self.host])
        else:
            self.zeroconf = zeroconf.Zeroconf()
        zeroconf.ServiceBrowser(self.zeroconf, self.domain, MDNSHandler(self))

        if ttl:
            GObject.timeout_add(ttl * 1000, self.shutdown)

        self.__running = True
        self.__mainloop = GObject.MainLoop()
        context = self.__mainloop.get_context()
        try:
            while self.__running:
                if context.pending():
                    context.iteration(True)
                else:
                    time.sleep(0.01)
        except KeyboardInterrupt:
            pass
        self.zeroconf.close()
        logger.info('MDNSListener.run()') 
开发者ID:masmu,项目名称:pulseaudio-dlna,代码行数:25,代码来源:mdns.py

示例2: start

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def start(self) -> None:
        """The ZeroConf service changed requests are handled in a separate thread so we don't block the UI.

        We can also re-schedule the requests when they fail to get detailed service info.
        Any new or re-reschedule requests will be appended to the request queue and the thread will process them.
        """

        self._service_changed_request_queue = Queue()
        self._service_changed_request_event = Event()
        try:
            self._zero_conf = Zeroconf()
        # CURA-6855 catch WinErrors
        except OSError:
            Logger.logException("e", "Failed to create zeroconf instance.")
            return

        self._service_changed_request_thread = Thread(target = self._handleOnServiceChangedRequests, daemon = True, name = "ZeroConfServiceChangedThread")
        self._service_changed_request_thread.start()
        self._zero_conf_browser = ServiceBrowser(self._zero_conf, self.ZERO_CONF_NAME, [self._queueService])

    # Cleanup ZeroConf resources. 
开发者ID:Ultimaker,项目名称:Cura,代码行数:23,代码来源:ZeroConfClient.py

示例3: add_service

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def add_service(self, zeroconf_obj, service_type, name):
    """Callback called by ServiceBrowser when a new mDNS service is discovered.

    Sometimes there is a delay in zeroconf between the add_service callback
    being triggered and the service actually being returned in a call to
    zeroconf_obj.get_service_info().  Because of this there are a few retries.
    Args:
      zeroconf_obj: The Zeroconf class instance.
      service_type: The string name of the service, such
        as '_privet._tcp.local.'.
      name: The name of the service on mDNS.
    """
    self.logger.info('Service added: "%s"', name)
    self.lock.acquire()
    info = zeroconf_obj.get_service_info(service_type, name, timeout=10000)
    retries = 5
    while info is None and retries > 0:
      self.logger.error('zeroconf_obj.get_service_info returned None, forces '
                        'retry.')
      time.sleep(0.1)
      retries -= 1
      info = zeroconf_obj.get_service_info(service_type, name, timeout=10000)
    if info is not None:
      self._added_service_infos.append(copy.deepcopy(info))
    self.lock.release() 
开发者ID:google,项目名称:cloudprint_logocert,代码行数:27,代码来源:_zconf.py

示例4: _find_zeroconf_threads

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def _find_zeroconf_threads():
  """Find all living threads that were started by zeroconf.

  Returns:
    List of thread objects started by zeroconf that are currently alive
    according to threading.enumerate().
  """
  def is_zeroconf_thread(thread):
    zeroconf_thread_objs = [
        zeroconf.Engine,
        zeroconf.Reaper,
        zeroconf.ServiceBrowser
    ]
    for obj in zeroconf_thread_objs:
      if isinstance(thread, obj):
        return True
    return False
  zeroconf_threads = filter(is_zeroconf_thread, threading.enumerate())
  return zeroconf_threads


# pylint: disable=dangerous-default-value
# The default case, [] is explicitly handled, and common. 
开发者ID:google,项目名称:cloudprint_logocert,代码行数:25,代码来源:_zconf.py

示例5: __init__

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def __init__(self, logger, wifi_interfaces=[]):
    """Initialization requires a logger.

    Args:
      logger: initialized logger object.
      if_addr: string, interface address for Zeroconf, None means
               all interfaces.
    """
    self.logger = logger
    self.l = _Listener(logger)
    if not wifi_interfaces:
      self.z = Zeroconf()
    else:
      self.z = Zeroconf(wifi_interfaces)
    self.sb = ServiceBrowser(zc=self.z, type_='_privet._tcp.local.',
                             listener=self.l) 
开发者ID:google,项目名称:cloudprint_logocert,代码行数:18,代码来源:_zconf.py

示例6: __init__

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def __init__(self, deviceId):
        """
        Create and start a researcher for devices on network.

        Arguments:
        - deviceId : List of deviceIds (strings) to search.
        """
        self._zeroconf = Zeroconf()
        self._browser = []
        self._services = {}
        self._lock = threading.RLock()
        self._cond = threading.Condition(self._lock)
        for did in deviceId:
            self._browser.append(ServiceBrowser(self._zeroconf, '_arsdk-' +
                                                str(did) + '._udp.local.',
                                                self)) 
开发者ID:N-Bz,项目名称:bybop,代码行数:18,代码来源:Bybop_Discovery.py

示例7: locate_brewpi_services

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def locate_brewpi_services():
    zeroconf_obj = zeroconf.Zeroconf()
    listener = zeroconfListener()
    browser = zeroconf.ServiceBrowser(zeroconf_obj, "_brewpi._tcp.local.", listener)

    sleep(3)  # We have to give zeroconf services time to respond
    zeroconf_obj.close()

    return listener.brewpi_services 
开发者ID:thorrak,项目名称:fermentrack,代码行数:11,代码来源:mdnsLocator.py

示例8: locate_tiltbridge_services

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def locate_tiltbridge_services():
    zeroconf_obj = zeroconf.Zeroconf()
    listener = ZeroconfListener()
    browser = zeroconf.ServiceBrowser(zeroconf_obj, "_tiltbridge._tcp.local.", listener)

    sleep(3)  # We have to give zeroconf services time to respond
    zeroconf_obj.close()

    return listener.tiltbridge_services 
开发者ID:thorrak,项目名称:fermentrack,代码行数:11,代码来源:mdnsLocator.py

示例9: __init__

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def __init__(self) -> None:
        self._zero_conf = None  # type: Optional[Zeroconf]
        self._zero_conf_browser = None  # type: Optional[ServiceBrowser]
        self._service_changed_request_queue = None  # type: Optional[Queue]
        self._service_changed_request_event = None  # type: Optional[Event]
        self._service_changed_request_thread = None  # type: Optional[Thread] 
开发者ID:Ultimaker,项目名称:Cura,代码行数:8,代码来源:ZeroConfClient.py

示例10: target

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def target(self):
        """This thread scans for Bonjour/mDNS devices and emits
        deviceDiscovered signal with its name, address and info object"""
        self.zc = zeroconf.Zeroconf()
        self.browser = zeroconf.ServiceBrowser(
            self.zc, "_http._tcp.local.", handlers=[self.on_state_change])
        while True:
            time.sleep(0.5) 
开发者ID:opendata-stuttgart,项目名称:airrohr-firmware-flasher,代码行数:10,代码来源:workers.py

示例11: run

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def run(self):
        zeroconf = Zeroconf()
        browser = ServiceBrowser(zeroconf, GOOGLE_CAST_IDENTIFIER, self)

        try:
            with self.run_condition:
                self.run_condition.wait()

            self.logger.debug("end of run-body (discovery)")

        finally:
            browser.cancel()
            zeroconf.close() 
开发者ID:nohum,项目名称:chromecast-mqtt-connector,代码行数:15,代码来源:discovery.py

示例12: start

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def start():
    ZC = zeroconf.Zeroconf()
    listener = AirplayListener()
    browser = zeroconf.ServiceBrowser(ZC, "_airplay._tcp.local.", listener)
    started = True
    if DEBUG:
        print("Listener started.")

# To stop it: 
开发者ID:openairplay,项目名称:openairplay,代码行数:11,代码来源:discovery.py

示例13: start

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def start(self):
        # Use self as the listener class because I have add_service and remove_service methods
        self.browser = ServiceBrowser(self._zeroconf, self._service_type, self) 
开发者ID:gilestrolab,项目名称:ethoscope,代码行数:5,代码来源:device_scanner.py

示例14: run

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def run(self):
        listener = Listener()
        print("Searching. Press q to stop")
        browser = zeroconf.ServiceBrowser(
            zeroconf.Zeroconf(), self.args["service"], listener)
        key = ""
        while key.lower() != "q":
            key = readchar.readchar()
        browser.cancel()
        print("") 
开发者ID:ElevenPaths,项目名称:HomePWN,代码行数:12,代码来源:mdns.py

示例15: run

# 需要导入模块: import zeroconf [as 别名]
# 或者: from zeroconf import ServiceBrowser [as 别名]
def run(self):
        listener = Listener()
        try:
            timeout = int(self.args["timeout"])
        except:
            timeout = 5
        print(f"Searching Xiaomi devices. Timeout: {timeout} seconds")
        browser = zeroconf.ServiceBrowser(zeroconf.Zeroconf(), "_miio._udp.local.", listener)
        sleep(timeout)
        browser.cancel()
        print("") 
开发者ID:ElevenPaths,项目名称:HomePWN,代码行数:13,代码来源:xiaomi-devices-passive.py


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