RMI connection question

C

coder_1024

I'm developing a Java RMI client/server application.

On the server side, I create a registry on port X, then create my
object on port X and bind to the registry.

On the client side, I do a Naming.lookup call specifying the server
host and port X along with the object name. This gives me back the
object reference and everything works.

The problem occurs when I run my server behind a router. I setup
port-forwarding on my router to route port X to the machine running
the server.

Problem is, the registry is returning the IP of the server which isn't
valid on the other side of the router and the client is then unable to
connect to the object.

Is it possible to skip the object registry entirely and just connect
up to a specified host and port number from the client? I need some
way to, on the client side, get the server object without using the
registry, i.e. just tell it the host and port number and connect up
directly to the remote object. I think this would solve my router
problems...
 
C

coder_1024

I'm developing a Java RMI client/server application.

On the server side, I create a registry on port X, then create my
object on port X and bind to the registry.

On the client side, I do a Naming.lookup call specifying the server
host and port X along with the object name. This gives me back the
object reference and everything works.

The problem occurs when I run my server behind a router. I setup
port-forwarding on my router to route port X to the machine running
the server.

Problem is, the registry is returning the IP of the server which isn't
valid on the other side of the router and the client is then unable to
connect to the object.

Is it possible to skip the object registry entirely and just connect
up to a specified host and port number from the client? I need some
way to, on the client side, get the server object without using the
registry, i.e. just tell it the host and port number and connect up
directly to the remote object. I think this would solve my router
problems...

I found a way to get around the problem. It may be a little hacky but
it works.

1. On the client side, when the user specifies the host to connect to,
I store this host using System.setProperty().
2. I provide custom server and client socket factories for my
server-side object. The client factory uses System.getProperty() to
find the host intended by the client. If found, it overrides the
requested host and uses the one from getProperty() instead.

The result is that RMI sockets created on the client side are forced
to connect to the intended host, not the one returned by the object
registry. Basically, the host as returned in the reference from the
object registry is ignored, and the host we know we really want to
connect to is used instead.
 
E

EJP

-Djava.rmi.server.hostname

coder_1024 said:
I found a way to get around the problem. It may be a little hacky but
it works.

1. On the client side, when the user specifies the host to connect to,
I store this host using System.setProperty().
2. I provide custom server and client socket factories for my
server-side object. The client factory uses System.getProperty() to
find the host intended by the client. If found, it overrides the
requested host and uses the one from getProperty() instead.

The result is that RMI sockets created on the client side are forced
to connect to the intended host, not the one returned by the object
registry. Basically, the host as returned in the reference from the
object registry is ignored, and the host we know we really want to
connect to is used instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top