Here you can find the source of getIp(SocketAddress socketAddress)
public static String getIp(SocketAddress socketAddress)
//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); } }