Java Socket Address Get getIp(SocketAddress socketAddress)

Here you can find the source of getIp(SocketAddress socketAddress)

Description

get Ip

License

Apache License

Declaration

public static String getIp(SocketAddress socketAddress) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.net.InetSocketAddress;
import java.net.SocketAddress;

public class Main {
    public static String getIp(SocketAddress socketAddress) {

        if (socketAddress instanceof InetSocketAddress) {

            InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
            String ip = inetSocketAddress.getAddress().toString();
            if (ip.charAt(0) == '/') {
                return ip.substring(1);
            }//from w  w  w . j a  v a  2s .com
            return ip;
        }

        throw new IllegalStateException(
                "unknown socketaddress type:" + socketAddress.getClass() + "," + socketAddress);
    }
}

Related

  1. getInetSocketAddress(String endpoint)
  2. getInetSocketAddress(String endpointURI, int defaultPort)
  3. getInetSocketAddress(String s, String mainHost)
  4. getInetSocketAddressFromStringStrict(String s)
  5. getInetSocketTransportAddressConstructor()
  6. getIpAddress(Socket socket)
  7. getIpAddress(SocketAddress sa)
  8. getIpAsString(SocketAddress address)
  9. getLocalAddress(Socket socket)