LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-15-2004, 02:03 PM   #1
qiye
LQ Newbie
 
Registered: Sep 2004
Posts: 1

Rep: Reputation: 0
Java code to get inet address in linux


hi all.. i encounter a problem. I have a servlet that is deploy in apache tomcat which is running the linux OS. I need to get the inet address in order to let client access the server.

I coded these lines of code in my servlet:

InetAddress localhost = InetAddress.getLocalHost();
String hostAddr = localhost.getHostAddress();

However, i encounter null for hostAddr but it works perfectly well in Windows. I want to get the ip address of the server, example: 203.204.423.52 and not 127.0.0.1.

Anyone knows how to solve the above issue? Do i need to make any changes to the coding to cater for linux? Any suggestion or comment is welcome. Thanks!
 
Old 09-15-2004, 02:23 PM   #2
mirradric
Member
 
Registered: May 2004
Location: Singapore
Distribution: Debian woody and debian sarge
Posts: 188

Rep: Reputation: 31
I got "127.0.0.1" for that rather than null.
Anyway one way to overcome this is to use the NetworkInterface class instead to get the ip address for the interface that you want. The class is only in j2se 1.4 or greater though.

Is there a way to make the original code work??

Last edited by mirradric; 09-15-2004 at 02:24 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why won't this Java code work? ludeKing Programming 9 05-28-2004 12:32 PM
Java, code compiles and supposedly runs fine in windows, but not linux exodist Programming 4 03-16-2004 01:47 PM
how to invoke a linux command inside a java code ? kusum Linux - Software 2 11-23-2003 02:19 PM
Java application startup using inet.d lashworth Linux - Networking 0 08-28-2003 03:35 PM
Win95 slow inet access via Linux MASQ raypen Linux - Networking 0 11-28-2002 10:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration