List of utility methods to do Socket Address Get
InetSocketAddress | getConnectAddress(InetSocketAddress addr) Returns InetSocketAddress that a client can use to connect to the server. if (!addr.isUnresolved() && addr.getAddress().isAnyLocalAddress()) { try { addr = new InetSocketAddress(InetAddress.getLocalHost(), addr.getPort()); } catch (UnknownHostException uhe) { addr = new InetSocketAddress("127.0.0.1", addr.getPort()); InetSocketAddress canonicalAddress = new InetSocketAddress(addr.getAddress().getCanonicalHostName(), ... |
String | getConnString(SocketAddress address) get Conn String String addrStr = address.toString(); if (addrStr.contains("/")) { addrStr = addrStr.substring(addrStr.indexOf("/") + 1); return addrStr; |
InetSocketAddress | getDestination(InetSocketAddress server) get Destination if (server.getAddress().isAnyLocalAddress()) { server = new InetSocketAddress(InetAddress.getLoopbackAddress(), server.getPort()); return server; |
InetSocketAddress | getDestinationInetSocketAddress(URI uri, int defaultPort) Get a socket address for a URI destination, resolving the host name if necessary. final String host = uri.getHost(); if (host == null) { return null; final int length = host.length(); if (length == 0) { return null; int port = uri.getPort(); if (port == -1) port = defaultPort; if (port == -1) { return null; return new InetSocketAddress(host, port); |
String | getHostAddress(InetSocketAddress addr) Returns the address of the host minimizing DNS lookups. String hostToAppend = ""; if (addr.isUnresolved()) { hostToAppend = addr.getHostName(); } else { hostToAppend = addr.getAddress().getHostAddress(); return hostToAppend; |
String | getHostAddress(InetSocketAddress address) get Host Address if (address.isUnresolved()) { return (address.getHostName()); } else { return (address.getAddress().getHostAddress()); |
String | getHostName(SocketAddress socketAddress) get Host Name if (socketAddress == null) { return null; if (socketAddress instanceof InetSocketAddress) { InetAddress addr = ((InetSocketAddress) socketAddress).getAddress(); if (addr != null) { return addr.getHostAddress(); return null; |
String | getHostNameNoResolve(InetSocketAddress address) get Host Name No Resolve InetAddress i_address = address.getAddress(); if (i_address == null) { return (address.getHostName()); } else { String str = i_address.toString(); int pos = str.indexOf('/'); if (pos == -1) { System.out.println("InetAddress::toString not returning expected result: " + str); ... |
String | getHostPortString(InetSocketAddress addr) Compose a "host:port" string from the address. return addr.getHostName() + ":" + addr.getPort(); |
String | getHostPortString(InetSocketAddress addr) Compose a "host:port" string from the address. return addr.getHostName() + ":" + addr.getPort(); |