def validate(self, context): """ Component validated """ # Get the framework UID self._fw_uid = context.get_property(pelix.constants.FRAMEWORK_UID) # Get the host address self._address = socket.inet_aton( socket.gethostbyname(socket.gethostname())) # Prepare Zeroconf self._zeroconf = mdns.Zeroconf("0.0.0.0") # Register the dispatcher servlet as a service self.__register_servlet() # Listen to our types self._browsers.append( mdns.ServiceBrowser(self._zeroconf, ZeroconfDiscovery.DNS_DISPATCHER_TYPE, self)) self._browsers.append( mdns.ServiceBrowser(self._zeroconf, self._rs_type, self)) _logger.debug("Zeroconf discovery validated")
def main(ip=None): print("Multicast DNS Service Discovery for Python, version", Zeroconf.__version__) r = Zeroconf.Zeroconf(ip or '') host_ip = socket.gethostbyname(socket.gethostname()) try: print("1. Testing registration of a service...") desc = { 'version': '0.10', 'key_a': 'value_for_key_b', 'key_b': 'value_for_key_b' } info = Zeroconf.ServiceInfo("_http._tcp.local.", "My Service Name._http._tcp.local.", socket.inet_aton(host_ip), 1234, 0, 0, desc) print(" Registering service...") r.registerService(info) print(" Registration done.") print("2. Testing query of service information...") print( " Getting ZOE service:", str(r.getServiceInfo("_http._tcp.local.", "ZOE._http._tcp.local."))) print(" Query done.") print("3. Testing query of own service...") my_service = r.getServiceInfo("_http._tcp.local.", "My Service Name._http._tcp.local.") print(" Getting self:", str(my_service)) print(" Query done.") print("4. Testing unregister of service information...") r.unregisterService(info) print(" Unregister done.") finally: r.close()
def __init__(self, info_dict=None): self._info_dict = info_dict self._ttl = None self._mdns = mdns self._zeroconf = mdns.Zeroconf('') host_ip = socket.gethostbyname(socket.gethostname()) self._info = self._mdns.ServiceInfo(self._info_dict['type'], self._info_dict['service_name'], socket.inet_aton(host_ip), 1234, 0, 0, self._info_dict['description'])
def test_launch_and_close(self): rv = mdns.Zeroconf() rv.close()
def testLaunchAndClose(self): rv = mdns.Zeroconf() rv.close()