Java Local Host Get getLocalHost()

Here you can find the source of getLocalHost()

Description

Methods returns InetAddress for localhost

License

Apache License

Exception

Parameter Description
UnknownHostException if localhost could not be resolved

Return

InetAddress of the localhost

Declaration

private static InetAddress getLocalHost() throws UnknownHostException 

Method Source Code


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

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Main {
    /**//w  w w  . ja v  a 2 s.  c o  m
     * Methods returns InetAddress for localhost
     *
     * @return InetAddress of the localhost
     * @throws UnknownHostException if localhost could not be resolved
     */
    private static InetAddress getLocalHost() throws UnknownHostException {
        InetAddress addr;
        try {
            addr = InetAddress.getLocalHost();
        } catch (ArrayIndexOutOfBoundsException e) { //this is workaround for mac osx bug see AS7-3223 and JGRP-1404
            addr = InetAddress.getByName(null);
        }
        return addr;
    }
}

Related

  1. getLocalHost()
  2. getLocalHost()
  3. getLocalHost()
  4. getLocalHost()
  5. getLocalHost()
  6. getLocalHost()
  7. getLocalHost()
  8. getLocalHost()
  9. getLocalHost()