aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI hostname problem, Please Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI hostname problem, Please Help" Watch "RMI hostname problem, Please Help" New topic
Author

RMI hostname problem, Please Help

christy smile
Ranch Hand

Joined: Oct 15, 2001
Posts: 101
Hi, Ranchers,
I am running into the problem that
InetAddress.getLocalHost().getHostName() would only return the hostname, but not the domain name on Windows 2000. For instance, the full qualified hostname for my local machine is
christy.sanjose.tt.com, InetAddress.getLocalHost().getHostName()would only return "christy". Then when my client tries to look up the server with the fully qualified name "christy.sanjose.tt.com", a java.net.UnknownHostException is thrown. Has anyone encountered this problem?? Is there any walkaround for this?? Please help!
Thank you
Christy
Trevor Dunn
Ranch Hand

Joined: Jun 13, 2001
Posts: 84
Hi Christy,
The problem you are getting is referred to in bug id 4061709
this is really old. It says that the call to getHostName() is platform dependent on what it returns. However one person did post a solution, here it is, I have no idea if it works.


Hope it helps
Trevor
[This message has been edited by Trevor Dunn (edited December 11, 2001).]
christy smile
Ranch Hand

Joined: Oct 15, 2001
Posts: 101
Trevor,
Thank you for that code segment. However, it does not work either. Did you not running to this problem while implementing the your project? I believe that there should be some walk around for it. getHostName() does return the whole path name under Unix, just not under windows.
Anyone else ran into this problem before, please help.
Thanks!
Christy
Trevor Dunn
Ranch Hand

Joined: Jun 13, 2001
Posts: 84
No I did not run into this problem, probably becuase I never used that call. I just reread your post and this is related to the server discussion we had in another thread. There you originally said that if a user chooses network mode you start the server. Then I assume you use the getLocalHost to attach to the server. Like I said in the other thread. Your server should be entirely separate. It should be on a different machine (if possible) Therefore when you start your client in Network mode you should pass in the fully qualified name and use that to connect to the server. You should not assume the server will always be on the localhost
Trevor
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

I didn't use that, because of what Trevor just said. The server is seperate.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Have you tryed: InetAddress.getLocalHost().getHostAddress();

/Ren´┐Ż


Regards, Rene Larsen
Dropbox Invite
christy smile
Ranch Hand

Joined: Oct 15, 2001
Posts: 101
Hi, all,
Thank you for the replies. I am confused now.
Assume that the server is running on different machine than the client. In my server code, I need to register the hostname of that server with the naming space, like using Naming.rebind (url, this), where "url" is the hostname ortnumber for the server and "this" is the remote object. For me to get this "url", I used InetAddress.getLocalHost().getHostName(), is there anything wrong with this? Then, in the client side, the client needs to input the hostname and port number.
For instance, if my localhost is christy.sanjose.abc.com, on windows, InetAddress.getLocalHost().getHostName() would only return christy. So in the rmi registry, only rmi://christy/ is bound. In the client side when I enter christy.sanjose.abc.com, this name cannot be found. The problem does not exist in Unix.
I guess one way around this problem is to ask the user to explicitly provide a hostname when they start the server, so that I don't need to use the getLocalHost() to obtain the host info implicitly. Is this a good way to do it?
Another question I have is that does the rmiregistry starts before the server start? I am planning to create a GUI for the server as well, which allows the user to explicitly enter the hostname and port number for the server. Then, the rmiregistry is not supposed to start before the user enters the portnumber, since the rmiregistry must know the port number if one is specified. Is there anyway to start the rmiregistry as a separate process in the java process.
Your help is highly appreciated.
Trevor Dunn
Ranch Hand

Joined: Jun 13, 2001
Posts: 84
Hi Christy,
Do not use the getHostname, use getHostAddress() as Renee suggests. THis is what I used in my server. Then when you give the client the machine to attach to you can use the ip address, or if I am not mistaken the domain name also because your DNS will resolve that for you.
Trevor
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI hostname problem, Please Help