Solved

InetAddress and Java 1.3

Posted on 2001-08-15
7
845 Views
Last Modified: 2008-02-01
Hi,
I am developing a Applet and i want to get the host name of the computer i an running the applet on.
When i use JApplet.getCodeBase().getHost() I receive localhost instead of the server name.
When i use InetAddress.getLocalHost().getHostName() i get the same.
Any ideas ???
Thanx.
0
Comment
Question by:rotem_fo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Expert Comment

by:antons061400
ID: 6389225
probably you download that applet from your PC. (a web server take it from there)
0
 
LVL 92

Expert Comment

by:objects
ID: 6390532
Firstly the two thing you are try are different:

JApplet.getCodeBase().getHost()
Returns the host of the server where the applet was loaded.

InetAddress.getLocalHost().getHostName()
Returns the hostname of the client. This information is not accessible to unsigned applets and thus it is returning 'localhost' You need to sign the applet to be able to find the local hostname.
0
 

Author Comment

by:rotem_fo
ID: 6391439
Hi,
I used getCodeBase().getHost() .
Whenever i type the server's name in the address bar (in the internet explorer) i receive the machine name, if i type the ip address the getCodeBase().getHost() returns the ip entered in the address bar.
I am lost :(

R.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 6391482
Yes, getHost() returns the host part of the url, which is the ip address if that's what you've entered, or the hostname if you used that.
0
 
LVL 1

Assisted Solution

by:dviji
dviji earned 50 total points
ID: 6392827
You can get the HostName even you type ipaddress...
By using InetAddress.getByName(String) & InetAddress.getAllByName(String) methods.

i.e
 String hostName = getCodeBase().getHost();
 InetAddress inetAddress = InetAddress.getByName(hostName);
 inetAddress.getHostName();
 inetAddress.getHostAddress();

getByName() method will give you an InetAddress object. The input parameter must be string (if it is ipaddress or name that is not a matter).

Some hosts (most of the popular portals) may have many ipaddress (that is for load balancing) with a single name. In that case you can use getAllByName().

So the better solution is using getAllByName()... it will return an array of InetAddress...From that you can get the values.

ie. Your should looks like..

 String hostName = getCodeBase().getHost();
 InetAddress[] inetAddresses[] = InetAddress.getAllByName(hostName);

 for(int i=0;i<inetAddresses.length;i++)
 {
   inetAddresses[i].getHostName();
   inetAddresses[i].getHostAddress();
 }


...dviji


 

0
 

Expert Comment

by:CleanupPing
ID: 9061860
rotem_fo:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 20

Expert Comment

by:Venabili
ID: 9330425
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Split points between objects and dviji

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venabili
EE Cleanup Volunteer
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
login jsp example 24 105
Custom Java Application connects to database: Which one of the 20? 4 58
Which non-HTML GUI front end to use with Java? 3 67
Html split(text) 2 49
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question