Java Socket Address Get getLocalSocketAddress(String host, int port)

Here you can find the source of getLocalSocketAddress(String host, int port)

Description

get Local Socket Address

License

Apache License

Declaration

public static InetSocketAddress getLocalSocketAddress(String host, int port) 

Method Source Code

//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());
    }
}

Related

  1. getIp(SocketAddress socketAddress)
  2. getIpAddress(Socket socket)
  3. getIpAddress(SocketAddress sa)
  4. getIpAsString(SocketAddress address)
  5. getLocalAddress(Socket socket)
  6. getNetworkVersion(InetSocketAddress address)
  7. getOffsettedAddress(InetSocketAddress isa, int offset)
  8. getPort(InetSocketAddress socket)
  9. getPort(SocketAddress socketAddress)