Code example for InetSocketAddress

Methods: getAddress, getPort

0
 
import java.net.InetSocketAddress; 
 
public class NetUtils { 
  public static String getIpPortString(InetSocketAddress addr) {
    return addr.getAddress().getHostAddress() + ":" + addr.getPort();
  } 
 
  public static InetSocketAddress createSocketAddr(String addr) {
    String [] splitted = addr.split(":");
    return new InetSocketAddress(splitted[0], Integer.parseInt(splitted[1]));
  } 
}