LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Getting LocalHost on Java (https://www.linuxquestions.org/questions/programming-9/getting-localhost-on-java-441675/)

Panagiotis_IOA 05-04-2006 03:58 PM

Getting LocalHost on Java
 
Well, I just wrote a program for promting the localhost ip address. The problem is that takes as ip the l0 and not the eth0. As I know l0 is for Linux "talking" to its self.
Is there a way for defining to which adapter to check?

Thanks in advance.

destuxor 05-04-2006 07:57 PM

I think this example will show you what you need: http://www.rgagnon.com/javadetails/java-0390.html.

In Linux, the external IP address will usually be on the network interface "eth0". Localhost is always 127.0.0.1 (technically, anything with an IP address starting with 127 is a loopback adapter, but so many programs have "127.0.0.1" hardcoded into them that operating system programmers make sure that the "lo" is always 127.0.0.1). The loopback adapter is often used for IPC (inter-process communication).

If you'll look at the documentation, you'll see that you can "getByName".

mrcheeks 05-04-2006 08:53 PM

try playing with inetadress, i think there is a method to check if the address is the loopback address.

Panagiotis_IOA 05-05-2006 05:37 AM

Thanks destuxtor for the first link, that sovled the problem. I used getByName for getting the IPs of other hosts.


All times are GMT -5. The time now is 03:02 PM.