Change default RMI port (Java)

How can I change the default RMI port (1099). It can be either a JVM parameter or encoding, it does not matter. Thanks.

+6
java rmi
source share
2 answers

You can specify it on the command line. From the RMI Tutorial :

By default, the registry starts on port 1099. To start the registry on another port, specify the port number on the command line. Remember to disable the CLASSPATH environment variable.

Microsoft Windows: start rmiregistry 2001 Solaris OS or Linux: rmiregistry 2001 & 

In your code, you use LocateRegistry.getRegistry (String host, int port) to find the registry by host name and port, as explained in Creating a Client Program in the lesson. (The same applies when implementing your server.)

+10
source share

You can specify your port when exporting a remote object, either through super (port, ...) or exportObject (remote, port, ...) depending on whether you are using or not distributing UnicastRemoteObject. If you renew Activatable, there are similar super () overloads with a port number. You can specify the registry port on the command line if you use it, otherwise through LocateRegistry.createRegistry () if you use this.

+3
source share

All Articles