This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm using Linux and in my server procedure I want to dtermine the IP address so I can bind my Objects accordingly. I have been using the follwoing methods in the server: InetAddress.getLocalHost().getHostAddress()); InetAddress.getLocalHost().getHostName()); byte test1 = InetAddress.getLocalHost().getAddress(); In windows these work just fine and return the proper IP, but in Linux I get an IP of 127.0.0.1. I can't seem to get the proper IP from the eth0. Any ideas on how to do this in the java.net? Or am I using the wrong thing? Thanks - Jeff
Jeff, Seems like the Linux JDK interpretation of the "local host" is just that - "localhost", i.e. the loopback address 127.0.0.1. Have you tried instantiating a <code>ServerSocket</code>, calling <code>accept</code> on it to bring it to life, then calling its <code>getInetAddress</code> method? I haven't tried it, but it sounds like it might work. jply
Joined: Oct 04, 2000
Jerry, sounds like a great idea. I implemented the idea and found out that the accept() method blocks untill a connection is made on that port. This doesn't help unfortunetly but I hit that port just to unblock the condition so I could get the code to continue. When it did continue I used the getInetAddress() on the socket that is created from the accept() method and then performed the getHostAddress() in the InetAddress object. But it returned 127.0.0.1. This is really confusing to me, but then again networking never was my forte. Thanks for the thought and anything else would be useful. Thanks - Jeff
Joined: Sep 19, 2000
Jeff, OK, neither of us knows the answer, so I'm moving this to Sockets and Internet Protocols. jply
[This message has been edited by Jerry Pulley (edited November 16, 2000).]