Solved

rmi and multiple IP addresses

Posted on 2003-10-29
10
358 Views
Last Modified: 2012-05-05
Hi,

I have written an rmi server and client. The server is on a machine that has 2 IP addresses, a local one (192.168.0.1) and a public one (195.*.*.*). Now everything works properly if the client points to the local ip. However when I try to point the client to the public ip address (which is what I would like to do), it doesn't "see" the server. The only solution I have found for this is to disable the ethernet card which provides the local ip address.

The following is where I think I am missing something out, (in the server that is)


          String hostnameProperty = "java.rmi.server.hostname";      
          java.util.Properties systemProperties = System.getProperties();
          String hostname = systemProperties.getProperty(hostnameProperty);
          hostname = java.net.InetAddress.getLocalHost().getHostAddress();

          Registry reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
          reg.rebind(ReceiveMessageInterface.SERVER_NAME,s);


Thanks for your help
0
Comment
Question by:ahmed_alsamarrai
  • 5
  • 3
10 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9643087
What is the value of 'hostnameProperty' btw?
0
 

Author Comment

by:ahmed_alsamarrai
ID: 9643356
Hi,

          String hostnameProperty = "java.rmi.server.hostname";  

is that what you wanted to know?

thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9643505
Sorry, LOL

'hostname' not 'hostnameProperty'
0
 

Author Comment

by:ahmed_alsamarrai
ID: 9647072
I'm not sure I understand! if I print out the value of hostname, I get the local ip address: 192.168.0.1

To be honest, I'm not sure exactly what is the purpose of each line. What I require is that the server "binds" on the public ip address and not the local one.

thanks
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 86

Expert Comment

by:CEHJ
ID: 9651951
>>To be honest, I'm not sure exactly what is the purpose of each line

Nor am i ;-) Certainly the fourth line overwrites the third.

Try doing

hostname

at the command line, then

InetAddress public = InetAddress.getByName(<put the hostname in here>);
0
 

Author Comment

by:ahmed_alsamarrai
ID: 9669015
ok...

I think that the only things which have an effect on the rmi Server are the last 2 lines of my code:
          Registry reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
          reg.rebind(ReceiveMessageInterface.SERVER_NAME,s);

as I commented the rest out and it did not have any effect....

it still always uses the local ip address

by the way, s, which appears in the second line is the rmi Server object

i just don't know where to specify the public ip address...

thanks
0
 

Author Comment

by:ahmed_alsamarrai
ID: 9855179
Hi,

what am i supposed to do with the public string afterwards... how do I tell the rmi server to use that? basically, how do I tell it to use the public ip address?

thanks
0
 

Author Comment

by:ahmed_alsamarrai
ID: 9855228
ok i just figured it out..... at the command prompt, when I run the program i do:

java -Djava.rmi.server.hostname=195.x.x.x RmiServer

thanks anyway
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11464545
PAQed, with points refunded (50)

modulo
Community Support Moderator
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now