0

I am using InetAddress and I am getting a false response when trying to reach the server. The server is the current latop. Below is the code:

public static void main(String[] args) {
    InetAddress i = InetAddress.getByName("ip address of current machine");
    System.out.println(i.isReachable(0)); // prints false
    System.out.println(i.getHostName());
}

The above prints false and then the actual host name. How can the host name be detected and the same machine is not reachable. What am I doing wrong?

user3189663
  • 211
  • 4
  • 18

1 Answers1

0

The hostname is resolved via DNS. The host doesn't have to be up for that to work. It's like the phone book. It shows your number 24 hours a day, even though you're out or not answering for 8 hours a day at least.

user207421
  • 305,947
  • 44
  • 307
  • 483