Random port numbers showing up during debugging of RMI application

420 Views Asked by At

I have written a sample RMI application that simply calculates the sum of two numbers.

My server.policy looks like:

grant {
permission java.net.SocketPermission "123.4.567.890:1024-", "accept, resolve";
};

and my client.policy looks like:

grant codeBase "file:/C:/Users/user/Documents/My_Workspace/Project/RMI/-" {
permission java.net.SocketPermission "123.4.567.890:1024-", "connect, resolve";
};

I read the documentation on the syntax of a policy file and learned that when you put a dash after the port number it means "this port number and greater". I don't know much about ports but, if i leave the dash out of the server.policy i get java.security.AccessControlException with random port numbers (seemingly between 50,000 and 65,000) but, if i leave the dash out of the client.policy i get the same java.security.AccessControlException with port number 1099 being the culprit every time.

I am wondering if there is a way to avoid having to put the dash in my policy files in order to allow my RMI application to work correctly.

Also, if it helps or matters at all i am specifying port 1099 in my createRegistry() and getRegistry() methods in the server/client respectively.

1

There are 1 best solutions below

1
user207421 On

There is. If:

  1. You start the Registry from within the server JVM via LocateRegistry.createRegistry()
  2. You construct or export all your remote objects from the same JVM specifying either port 1099 or port 0, or not specifying a port number at all, and
  3. There are no socket factories in either (1) or (2), or the socket factories all have plausible implementations of the equals() method

all remote objects will share the same port, port 1099.

But why is a dash in a .policy file such a big deal?