Back to project page mha-android.
The source code is released under:
Copyright (c) 2011-2012 Cameron Porter, Ryan Brown http://github.com/camporter/mha-android Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated...
If you think the Android project mha-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.teamacra.myhomeaudio.discovery; /* w w w . ja v a 2 s.c om*/ import java.io.IOException; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Collections; import java.util.Enumeration; import java.util.Random; import javax.jmdns.JmDNS; import javax.jmdns.JmmDNS; import javax.jmdns.ServiceInfo; import android.net.wifi.WifiManager.MulticastLock; import android.util.Log; public class MDNSDiscovery { public static final String DISCOVERY_TYPE = "_myhomeaudio._tcp.local."; public MDNSDiscovery() { } public String run(MulticastLock lock) { lock.acquire(); try { // Discovery must be set on all possible network interfaces, so go // through them all Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface netint : Collections.list(nets)) { // Each interface can have multiple addresses Enumeration<InetAddress> inetAddresses = netint.getInetAddresses(); for (InetAddress inetAddress : Collections.list(inetAddresses)) { // Ignore loopback or link-local //if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress()) { JmDNS jmdns = JmDNS.create(inetAddress, null); ServiceInfo[] serviceInfos = jmdns.list(DISCOVERY_TYPE); jmdns.close(); //} } } } catch (IOException e) { e.printStackTrace(); } lock.release(); return null; } }