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

StringgetAddress(InetSocketAddress address)
Return the Address in the format compatible with FTP argument
InetAddress servAddr = address.getAddress();
int servPort = address.getPort();
return servAddr.getHostAddress().replace('.', ',') + ',' + (servPort >> 8) + ',' + (servPort & 0xFF);
StringgetAddress(SocketAddress address)
get Address
if (address == null) {
    return null;
if (address instanceof InetSocketAddress) {
    InetSocketAddress isa = (InetSocketAddress) address;
    return isa.getAddress().getHostAddress() + ":" + isa.getPort();
} else {
    return address.toString();
...
InetAddressgetAddress(SocketAddress address)
An utility method to get the InetAddress from the SocketAddress .
return getResolved(address).getAddress();
StringgetAddressFirst(InetSocketAddress inetSocketAddress)
Returns the String form of the IP address of the given InetSocketAddress , or the hostname if it has not been resolved.
if (inetSocketAddress == null) {
    return null;
InetAddress inetAddress = inetSocketAddress.getAddress();
if (inetAddress != null) {
    return inetAddress.getHostAddress();
return inetSocketAddress.getHostName();
...
StringgetAddressRepresentation(final SocketAddress address)
Represents the address as string
final InetSocketAddress inetAddr = (InetSocketAddress) address;
return inetAddr.getAddress().getHostAddress() + "@" + inetAddr.getPort();
StringgetAddrString(final SocketAddress address)
get Addr String
if (address == null) {
    return null;
if (address instanceof InetSocketAddress) {
    final InetSocketAddress socketAddr = (InetSocketAddress) address;
    final InetAddress inetAddr = socketAddr.getAddress();
    return (inetAddr != null ? inetAddr.getHostAddress() : socketAddr.getHostName()) + ":"
            + socketAddr.getPort();
...
ServerSocketgetAlreadyBoundServerSocket(String address, int port, boolean ssl, boolean useChannels)
get Already Bound Server Socket
String key = makeKey(address, port, ssl, useChannels);
ServerSocket serverSocket = mBoundSockets.get(key);
return serverSocket;
InetSocketAddressgetBestAddress(InetSocketAddress addr)
get Best Address
Enumeration<NetworkInterface> networkIfs = NetworkInterface.getNetworkInterfaces();
while (networkIfs.hasMoreElements()) {
    NetworkInterface networkIf = networkIfs.nextElement();
    if (!networkIf.isLoopback() && networkIf.isUp()) {
        boolean found = false;
        for (InterfaceAddress a : networkIf.getInterfaceAddresses()) {
            if (a.getAddress().getClass().equals(addr.getAddress().getClass())) {
                addr = new InetSocketAddress(a.getAddress(), addr.getPort());
...
StringgetCanonicalConnectionAddress(InetSocketAddress address)
get Canonical Connection Address
return "tcp://" + address.getAddress().getCanonicalHostName() + ":" + address.getPort();
IntegergetClientPort(SocketAddress socketAddress)
get Client Port
if (!(socketAddress instanceof InetSocketAddress)) {
    return null;
InetSocketAddress remoteAddress = (InetSocketAddress) socketAddress;
return remoteAddress.getPort();