當前位置: 首頁>>代碼示例>>Python>>正文


Python zeroconf.Zeroconf方法代碼示例

本文整理匯總了Python中zeroconf.Zeroconf方法的典型用法代碼示例。如果您正苦於以下問題:Python zeroconf.Zeroconf方法的具體用法?Python zeroconf.Zeroconf怎麽用?Python zeroconf.Zeroconf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在zeroconf的用法示例。


在下文中一共展示了zeroconf.Zeroconf方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: mDNSinit

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [as 別名]
def mDNSinit(type, name):
    deviceType = '_' + type
    desc = {'deviceName': name}
    # desc = {}

    info = ServiceInfo(deviceType + "._tcp.local.",
                       name + "." + deviceType +"._tcp.local.",
                       socket.inet_aton(deviceIP), wsPort, 0, 0,
                       desc, name + ".local.")

    zeroconf = Zeroconf()
    zeroconf.register_service(info)

    # if isDebugAll() is True:
    BLINKER_LOG_ALL('deviceIP: ', deviceIP)
    BLINKER_LOG_ALL('mdns name: ', name)

    BLINKER_LOG('mDNS responder init!') 
開發者ID:blinker-iot,項目名稱:blinker-py,代碼行數:20,代碼來源:BlinkerLinuxWS.py

示例2: __init__

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [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

示例3: run

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [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

示例4: start

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [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

示例5: add_service

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [as 別名]
def add_service(self, zeroconf, type, name):
        """
        Method required to be a Zeroconf listener. Called by Zeroconf when a "_device._tcp" service
        is registered on the network. Don't call directly.
        
        sample values:
        type = '_device._tcp.local.'
        name = 'DEVICE000._device._tcp.local.'
        """

        
        try:
            info = zeroconf.get_service_info(type, name)

            if info:
                #ip = socket.inet_ntoa(info.address)
                ip = socket.inet_ntoa(info.addresses[0])
                self.add( ip, name )
        
        except Exception as error:
            logging.error("Exception trying to add zeroconf service '"+name+"' of type '"+type+"': "+str(error)) 
開發者ID:gilestrolab,項目名稱:ethoscope,代碼行數:23,代碼來源:device_scanner.py

示例6: add_service

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [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

示例7: wait_for_service_add

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [as 別名]
def wait_for_service_add(t_seconds, target_service, listener):
  """Wait for a service to be added.

      Args:
        t_seconds: Time to listen for mDNS records, in seconds.
                   Floating point ok.
        service: string, The service to wait for
        listener: _Listener object, the listener to wait on
      Returns:
        If Add event observed, return the Zeroconf information class; otherwise,
        return None
    """
  t_end = time.time() + t_seconds
  while time.time() < t_end:
    services = listener.services()
    for service in services:
      if target_service in service.properties['ty']:
        return service
    time.sleep(1)
  return None 
開發者ID:google,項目名稱:cloudprint_logocert,代碼行數:22,代碼來源:_zconf.py

示例8: __init__

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [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

示例9: start

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [as 別名]
def start():
	global localHTTP, zeroconf, info, httpthread
	ip = get_local_address()
	logging.info("Local IP is " + ip)

	desc = {'version': '0.1'}
	info = ServiceInfo("_http._tcp.local.",
			"Alexa Device._http._tcp.local.",
			socket.inet_aton(ip), alexa_params.LOCAL_PORT, 0, 0,
			desc, alexa_params.LOCAL_HOST + ".")
	zeroconf = Zeroconf()
	zeroconf.registerService(info)
	logging.info("Local mDNS is started, domain is " + alexa_params.LOCAL_HOST)
	localHTTP = HTTPServer(("", alexa_params.LOCAL_PORT), alexa_http_config.AlexaConfig)
	httpthread = threading.Thread(target=localHTTP.serve_forever)
	httpthread.start()
	logging.info("Local HTTP is " + alexa_params.BASE_URL)
	alexa_control.start() 
開發者ID:devicehive,項目名稱:AlexaDevice,代碼行數:20,代碼來源:alexa_auth.py

示例10: main

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [as 別名]
def main():
        zeroconf = Zeroconf()
        listener = MyListener()
        browser = ServiceBrowser(zeroconf, "_ewelink._tcp.local.",listener= listener)
        while True:
                if listener.all_sub_num>0:
                    dict=listener.all_info_dict.copy()
                    for x in dict.keys():
                        info=dict[x]
                        info=zeroconf.get_service_info(info.type,x)
                        if info!= None:
                            data=info.properties
                            cur_str=x[8:18]+"  "+parseAddress(info.address)+"  "+str(info.port)+"  "   +str(data)
                            print(cur_str)
                if len(listener.all_del_sub)>0:
                        for x in listener.all_del_sub:
                            cur_str=x[8:18]+"\nDEL"
                            print(cur_str)
                time.sleep(0.5) 
開發者ID:itead,項目名稱:Sonoff_Devices_DIY_Tools,代碼行數:21,代碼來源:mdns.py

示例11: announce_zeroconf

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [as 別名]
def announce_zeroconf(self):
        desc = {'name': 'SigmaTCP',
                'vendor': 'HiFiBerry',
                'version': hifiberrydsp.__version__}
        hostname = socket.gethostname()
        try:
            ip = socket.gethostbyname(hostname)
        except Exception:
            logging.error("can't get IP for hostname %s, "
                          "not initialising Zeroconf",
                          hostname)
            return

        self.zeroconf_info = ServiceInfo(ZEROCONF_TYPE,
                                         "{}.{}".format(
                                             hostname, ZEROCONF_TYPE),
                                         socket.inet_aton(ip),
                                         DEFAULT_PORT, 0, 0, desc)
        self.zeroconf = Zeroconf()
        self.zeroconf.register_service(self.zeroconf_info) 
開發者ID:hifiberry,項目名稱:hifiberry-dsp,代碼行數:22,代碼來源:sigmatcp.py

示例12: __init__

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [as 別名]
def __init__(self, config):
        self.config = config

        # Use IPv6
        self.serveraddress = ('::', self.config.port)
        self.ServerClass = HTTPServerV6
        self.ServerClass.allow_reuse_address = False

        self.ip_addr = AirDropUtil.get_ip_for_interface(self.config.interface, ipv6=True)
        if self.ip_addr is None:
            if self.config.interface == 'awdl0':
                raise RuntimeError('Interface {} does not have an IPv6 address. '
                                   'Make sure that `owl` is running.'.format(self.config.interface))
            else:
                raise RuntimeError('Interface {} does not have an IPv6 address'.format(self.config.interface))

        self.Handler = AirDropServerHandler
        self.Handler.config = self.config

        self.zeroconf = Zeroconf(interfaces=[str(self.ip_addr)],
                                 ip_version=IPVersion.V6Only,
                                 apple_p2p=platform.system() == 'Darwin')

        self.http_server = self._init_server()
        self.service_info = self._init_service() 
開發者ID:seemoo-lab,項目名稱:opendrop,代碼行數:27,代碼來源:server.py

示例13: __init__

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [as 別名]
def __init__(self, config):
        self.ip_addr = AirDropUtil.get_ip_for_interface(config.interface, ipv6=True)
        if self.ip_addr is None:
            if config.interface == 'awdl0':
                raise RuntimeError('Interface {} does not have an IPv6 address. '
                                   'Make sure that `owl` is running.'.format(config.interface))
            else:
                raise RuntimeError('Interface {} does not have an IPv6 address'.format(config.interface))

        self.zeroconf = Zeroconf(interfaces=[str(self.ip_addr)],
                                 ip_version=IPVersion.V6Only,
                                 apple_p2p=platform.system() == 'Darwin')

        self.callback_add = None
        self.callback_remove = None
        self.browser = None 
開發者ID:seemoo-lab,項目名稱:opendrop,代碼行數:18,代碼來源:client.py

示例14: start_discovery

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [as 別名]
def start_discovery(callback=None):
    """
    Start discovering chromecasts on the network.

    This method will start discovering chromecasts on a separate thread. When
    a chromecast is discovered, the callback will be called with the
    discovered chromecast's zeroconf name. This is the dictionary key to find
    the chromecast metadata in listener.services.

    This method returns the CastListener object and the zeroconf ServiceBrowser
    object. The CastListener object will contain information for the discovered
    chromecasts. To stop discovery, call the stop_discovery method with the
    ServiceBrowser object.
    """
    listener = CastListener(callback)
    return listener, \
        ServiceBrowser(Zeroconf(), "_googlecast._tcp.local.", listener) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:19,代碼來源:discovery.py

示例15: _RegisterService

# 需要導入模塊: import zeroconf [as 別名]
# 或者: from zeroconf import Zeroconf [as 別名]
def _RegisterService(self, name, ip, port):
        # name: fully qualified service name
        self.service_name = '%s.%s' % (name, service_type)
        self.name = name
        self.port = port

        if ip == "0.0.0.0":
            print("MDNS brodcasted on all interfaces")
            interfaces = zeroconf.InterfaceChoice.All
            ip = self.gethostaddr()
        else:
            interfaces = [ip]

        self.server = zeroconf.Zeroconf(interfaces=interfaces)

        print("MDNS brodcasted service address :" + ip)
        self.ip_32b = socket.inet_aton(ip)

        self.server.register_service(
            zeroconf.ServiceInfo(service_type,
                                 self.service_name,
                                 self.ip_32b,
                                 self.port,
                                 properties=self.serviceproperties))
        self.retrytimer = None 
開發者ID:thiagoralves,項目名稱:OpenPLC_Editor,代碼行數:27,代碼來源:ServicePublisher.py


注:本文中的zeroconf.Zeroconf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。