Port questions with RMI

I'm getting confused about the RMI registry and the ports...

Here's the scenario:

I have a machine running a firewall. It blocks every ports by default unless I explicitly open them. I start rmiregistry using "rmiregistry 1099", just to be sure it is running on port 1099, so far so good.

I configured the firewall to open 1099 port and my clients can telnet to this box in port 1099 (using telnet myserver 1099).

Case 1:

If I publish a service into the registry, I have to use this constructor to specify that my service is running in this port 1100? (I cant use the 1099 port again because it is used). Do I need to open port 1100 in my firewall for my clients or is 1099 sufficient?

publicclass MyServiceImplextends UnicastRemoteObject{

public MyServiceImpl()throws RemoteException{

super(1100);

}

...

}

Case 2:

Suppose I do not run rmiregistry locally in the same JVM instead , and just use the default constructor,

publicclass MyServiceImplextends UnicastRemoteObject{

public MyServiceImpl()throws RemoteException{

super();

}

...

}

...

// Running rmi registry locally on same JVM

Registry registry = LocateRegistry.createRegistry( 1099 );

MyServiceImpl obj =new MyServiceImpl( );

...

Does it mean I only need port 1099 opened in my firewall for my clients? I'm running JDK 1.5.0_10 if that matters.

Thanks in advance,

Gary

[2199 byte] By [garytse_hka] at [2007-11-27 6:00:51]
# 1

You need a port for the RMI Registry. As you note, 1099 is the default. It doesn't matter where the registry runs, your JVM or its own.

You need a port for the Clients to call the Server.

The user ports are about 50000 and up. Google to find a write up on port usage.

When you export your remote object you can choose the port for communication: e.g. UnicastRemoteObject.exportObject(impl, 50001);

If you don't explicitly choose a port, then an autonomous port is chosen.

cooper6a at 2007-7-12 16:39:40 > top of Java-index,Core,Core APIs...
# 2

I think you meant 'anonymous' but what you really mean is that the system chooses the port in the space 1024->65535. If you need to open ports in your firewall you need to use a fixed port when exporting.

If you run the Registry inside your JVM with LocateRegistry.createRegistry() you can use port 1099 for everything. Unless you are using socket factories, which there is rarely any need to do other than for SSL.

ejpa at 2007-7-12 16:39:40 > top of Java-index,Core,Core APIs...
# 3
Yes, anonymous is what I meant.I've never used an embedded registry. Interesting about it sharing the same port as the server. I don't know if this is good or bad when 1099 is used.
cooper6a at 2007-7-12 16:39:40 > top of Java-index,Core,Core APIs...
# 4

Just a comment on the embedded registry: It may work for some applications, but it is a major pain in the butt when your server has multiple appplications - all using RMI.

The basic problem is that an error in the app that started the regisrty can cause all of the other services to become inaccessible.

bschauwejavaa at 2007-7-12 16:39:40 > top of Java-index,Core,Core APIs...
# 5
Many thanks for all the feedback !
garytse_hka at 2007-7-12 16:39:40 > top of Java-index,Core,Core APIs...