List of utility methods to do Socket Address Get
String | inetAddrToHoman(final InetSocketAddress sockAddr) inet Addr To Homan return sockAddr.getAddress().getHostAddress() + ":" + sockAddr.getPort(); |
String | inetSocketAddress2IpPort(InetSocketAddress addr) Format the InetSocketAddress into IP:Port string. String s = addr.toString(); int idx = s.indexOf('/') + 1; return s.substring(idx); |
String | IpToString(InetSocketAddress address) Ip To String String s = address.getAddress().getHostAddress() + ":" + address.getPort(); return s; |
boolean | isAddressDefined(InetSocketAddress address) probe to see if the address return !(address.getHostName().equals("0.0.0.0")); |
boolean | isLegalPeerAddress(@CheckForNull SocketAddress socketAddress) is Legal Peer Address if (socketAddress == null) return false; if (socketAddress instanceof InetSocketAddress) { InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; InetAddress inetAddress = inetSocketAddress.getAddress(); if (inetAddress == null) return false; if (inetAddress.isAnyLocalAddress()) ... |
boolean | isLocalAddress(Socket socket) Check if a socket is connected to a local address. InetAddress test = socket.getInetAddress(); if (test.isLoopbackAddress()) { return true; InetAddress localhost = InetAddress.getLocalHost(); String host = localhost.getHostAddress(); for (InetAddress addr : InetAddress.getAllByName(host)) { if (test.equals(addr)) { ... |
boolean | isSameAddress(SocketAddress a1, SocketAddress a2) Returns true if both SocketAddress es have the same InetAddress if (isUnresolved(a1) && isUnresolved(a2)) { if (getHostName(a1).equals(getHostName(a2))) { return true; return getResolved(a1).getAddress().equals(getResolved(a2).getAddress()); |
boolean | isUdpPortAvailable(InetSocketAddress localAddress) is Udp Port Available DatagramSocket ds = null; try { ds = new DatagramSocket(null); ds.setReuseAddress(false); ds.bind(localAddress); ds.close(); ds = null; return true; ... |
boolean | isUnresolved(SocketAddress address) Returns true if the given SocketAddress is unresolved. return ((InetSocketAddress) address).isUnresolved();
|
boolean | isValidMulticastAddress(final InetSocketAddress address) is Valid Multicast Address return address != null && address.getAddress() != null && address.getAddress().isMulticastAddress();
|