Here you can find the source of getLocalSocketAddress(String host, int port)
public static InetSocketAddress getLocalSocketAddress(String host, int port)
//package com.java2s; //License from project: Apache License import java.net.*; import java.util.regex.Pattern; public class Main { private static final Pattern LOCAL_IP_PATTERN = Pattern.compile("127(\\.\\d{1,3}){3}$"); public static InetSocketAddress getLocalSocketAddress(String host, int port) { return isInvalidLocalHost(host) ? new InetSocketAddress(port) : new InetSocketAddress(host, port); }/*from w w w .ja v a2 s .co m*/ public static boolean isInvalidLocalHost(String host) { return host == null || host.length() == 0 || host.equalsIgnoreCase("localhost") || host.equals("0.0.0.0") || (LOCAL_IP_PATTERN.matcher(host).matches()); } }