I am using Windows 8 with JDK 1.7. My IP address is 192.168.1.108, when I am running:
System.out.println(InetAddress.getLocalHost().equals(InetAddress.getByName("localhost")));
OR
System.out.println(InetAddress.getLocalHost().equals(InetAddress.getByName("127.0.0.1")));
Output - It's all false.
InetAddress.getLocalHost() - Output: 192.168.1.108
InetAddress.getByName("localhost") - Output: 127.0.0.1
Further more, my UDP server is binded on InetAddress.getLocalHost()
and it can't receive anything from the client if the client send packets to InetAddress.getByName("localhost")
. However, it works well if the client send to InetAddress.getLocalHost().
Port is corrent.
Anyone know the difference? Thanks in advance.