public String getLocalAddress() { InetAddress mcastAddr = ssdpMultiGroup.getAddress(); Enumeration addrs = ssdpMultiIf.getInetAddresses(); while (addrs.hasMoreElements()) { InetAddress addr = (InetAddress) addrs.nextElement(); if (mcastAddr instanceof Inet6Address && addr instanceof Inet6Address) return addr.getHostAddress(); if (mcastAddr instanceof Inet4Address && addr instanceof Inet4Address) return addr.getHostAddress(); } return ""; }
public boolean open(String addr, int port, String bindAddr) { try { ssdpMultiSock = new MulticastSocket(null); ssdpMultiSock.setReuseAddress(true); InetSocketAddress bindSockAddr = new InetSocketAddress(port); ssdpMultiSock.bind(bindSockAddr); ssdpMultiGroup = new InetSocketAddress(InetAddress.getByName(addr), port); ssdpMultiIf = NetworkInterface.getByInetAddress(InetAddress.getByName(bindAddr)); ssdpMultiSock.joinGroup(ssdpMultiGroup, ssdpMultiIf); } catch (Exception e) { Debug.warning(e); return false; } return true; }