Java Utililty Methods Socket Address Get

List of utility methods to do Socket Address Get

Description

The list of methods to do Socket Address Get are organized into topic(s).

Method

StringgetPort(InetSocketAddress socket)
get Port
return socket.getPort() + "";
IntegergetPort(SocketAddress socketAddress)
get Port
if (socketAddress == null) {
    return 0;
String address = socketAddress.toString();
return Integer.valueOf(address.substring(address.indexOf(':') + 1));
InetSocketAddressgetRandomLoopbackInetSocketAddress(final int port)
get Random Loopback Inet Socket Address
return new InetSocketAddress(getRandomLoopbackIpAddress(), port);
StringgetRawAddress(InetSocketAddress inetSocketAddress)
get Raw Address
InetAddress address = inetSocketAddress.getAddress();
return address != null ? address.getHostAddress() : inetSocketAddress.getHostName();
StringgetSimpleIpport(SocketAddress remoteAddr)
get Simple Ipport
if (remoteAddr == null) {
    return null;
if (remoteAddr instanceof InetSocketAddress) {
    InetSocketAddress addr = (InetSocketAddress) remoteAddr;
    return String.format("%s:%d", addr.getHostString(), addr.getPort());
return remoteAddr.toString();
...
StringgetSocketAddress(InetSocketAddress socket)
get Socket Address
return getHostName(socket) + ":" + getPort(socket);
StringgetSocketAddress(SocketAddress socketAddress)
get Socket Address
String address = socketAddress.toString();
int addressLength = address.length();
if (addressLength > 0) {
    if (address.startsWith("/")) {
        return address.substring(1);
    } else {
        final int delimeterIndex = address.indexOf('/');
        if (delimeterIndex != -1 && delimeterIndex < addressLength) {
...
SocketAddressgetSocketAddress(String hostHeader)
Get socket address from Host header.
int pivot = hostHeader.indexOf(':');
if (pivot == -1) {
    return new InetSocketAddress(hostHeader, 80);
return new InetSocketAddress(hostHeader.substring(0, pivot),
        Integer.parseInt(hostHeader.substring(pivot + 1, hostHeader.length())));
InetSocketAddress[]getSocketAddressList(String list, int defaultPort)
Parse space delimited addresss[:port] string and return array of InetSocketAddress.
return getSocketAddressList(list, defaultPort, null);
StringgetSocketConnectString(InetSocketAddress socketAddress)
get Socket Connect String
String host;
InetAddress address = socketAddress.getAddress();
if (address == null) {
    host = socketAddress.getHostString();
} else if (address.isAnyLocalAddress() || address.isLoopbackAddress()) {
    host = address.getCanonicalHostName();
} else {
    host = address.getHostName();
...