Java Socket Address Get getSocketAddress(String hostHeader)

Here you can find the source of getSocketAddress(String hostHeader)

Description

Get socket address from Host header.

License

Apache License

Parameter

Parameter Description
hostHeader e.g., Host: 127.0.0.1

Return

SocketAddress : responsible for resolving the host name.

Declaration


public static SocketAddress getSocketAddress(String hostHeader) 

Method Source Code


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

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

public class Main {
    /**/* w ww  . ja v a2s . co  m*/
     * Get socket address from Host header.
     * 
     * @param hostHeader
     *            e.g., Host: 127.0.0.1
     * @return SocketAddress : responsible for resolving the host name.
     */
    /*
     * Host names can be in two forms 1. localhost 2. localhost:1234. If the
     * default port 80 of HTTP is used then it omits port number else it
     * includes it.
     */
    public static SocketAddress getSocketAddress(String hostHeader) {
        int pivot = hostHeader.indexOf(':');
        if (pivot == -1) {
            return new InetSocketAddress(hostHeader, 80);
        }
        return new InetSocketAddress(hostHeader.substring(0, pivot),
                Integer.parseInt(hostHeader.substring(pivot + 1, hostHeader.length())));
    }
}

Related

  1. getRandomLoopbackInetSocketAddress(final int port)
  2. getRawAddress(InetSocketAddress inetSocketAddress)
  3. getSimpleIpport(SocketAddress remoteAddr)
  4. getSocketAddress(InetSocketAddress socket)
  5. getSocketAddress(SocketAddress socketAddress)
  6. getSocketAddressList(String list, int defaultPort)
  7. getSocketConnectString( InetSocketAddress socketAddress)
  8. inetAddrToHoman(final InetSocketAddress sockAddr)
  9. inetSocketAddress2IpPort(InetSocketAddress addr)