Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Default RMI Port (Java)

Tags:

java

rmi

How can I change the default RMI port (1099). It could be as JVM parameter or via coding, it doesn´t matter. Thanks.

like image 805
Ivan Bosnic Avatar asked Jun 02 '09 11:06

Ivan Bosnic


People also ask

What is the default port for RMI registry?

Specifies the RMI registry host and port at which the JMX contector stub is obtained by performing a JNDI lookup. The default port is 1099.

What ports does RMI use?

Setting RMI service ports By default port 1099 used by the RMI registry so make sure you opened this port in the firewall. However, this port is only used by the client to connect to the RMI registry and not for the communication between the stub and the remote object.

How do I set the Java RMI server hostname property at the server?

java.rmi.server.useLocalHostname rmi. server. hostname property is not specified and a fully qualified domain name for the localhost cannot be obtained. In order to force Java RMI to use the fully qualified domain name by default, you need to set the this property to true .


2 Answers

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

By default, the registry runs on port 1099. To start the registry on a different port, specify the port number on the command line. Do not forget to unset your CLASSPATH environment variable.

Microsoft Windows:

start rmiregistry 2001

Solaris OS or Linux:

rmiregistry 2001 &

In your code you use the LocateRegistry.getRegistry(String host, int port) override to locate the registry by hostname and port, as explained in the Creating a Client Program section of the tutorial. (The same applies when implementing your server.)

like image 80
Bill the Lizard Avatar answered Sep 23 '22 00:09

Bill the Lizard


You can specify your own port when exporting your remote object, either via super(port, ...) or exportObject(remote, port, ...) depending on whether you do or don't extend UnicastRemoteObject. If you extend Activatable there are similarly super() overloads with a port number. You can specify the Registry's port on the command line if you use that, otherwise via LocateRegistry.createRegistry() if you use that.

like image 34
user207421 Avatar answered Sep 20 '22 00:09

user207421