RMI & Server using random ports
843793Nov 26 2003 — edited Nov 26 2003I realise this has been asked many times before, and I have read hundreds of posts in this forum, and have implemented the solutions detailed, but am still having a problem.
I have a simple RMI app - client runs a remote method on the server and expects a String value back. I have implemented the following ...
- Create an interface which extends Remote
- Create a server implementation which extends UnicastRemoteObject and implements my server interface
- Create a custom RMISocketFactory so that all socket attempts on port 0 (random) are assigned to port 1201
- Call the constructor of UnicastRemoteObject passing it port 1201 in the constructor of the server
- Set the RMISocketFactory to my custom factory in the constructor of the server
- Create the RMI registry on port 1200 and do a .rebind(<name>, this)
- Create a custom java.policy file for both client and server to grant SocketPermission on ports 1200 and 1201 only.
So I have done everything detailed in previous posts. The server component runs fine. When I try to connect with the client the 1st thing we do is lookup the RIM registry.
LocateRegistry.getRegistry works OK, but when I do Naming.lookup on the registry, the server returns and AccessDenied error on a random high-numbered port on the client (usually 35???). The client also returns and UnmarshalException.
Why, when I have done all of the above, does the server still appear to want to use a random port, rather that 1201 as I have specified.
Any help much appreciated.
Greg.