Solved

rmi and multiple IP addresses

Posted on 2003-10-29
10
378 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
[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
  • 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 

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

Industry Leaders: 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!

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

688 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