Solved

rmi and multiple IP addresses

Posted on 2003-10-29
10
364 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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
 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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:

777 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