Hey everyone,
I have an RMI server running on a server. When a client is located on the same machine as the server, it is able to connect to it fine. However, when the client is remote, it is unable to do so. I poked around the internet a bit, and came across "-Djava.rmi.server.hostname" for setting up the server's ip address correctly. I've tried to get that to work but with no luck. I think that I may be creating the RMI registry wrong, or perhaps just using the command wrong. Any help on this would be great.
import java.io.*;
import java.net.*;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RMISecurityManager;
public class Server {
public static void main(String args[]) {
settings st = new settings();
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(is);
String portNum, registryURL;
try {
//Start the RMI registry on port 7504
startRegistry(7504);
// Create the rmi object and register is with the rmi registry.
rmiImpl rmi = new rmiImpl();
registryURL = "rmi://localhost:7504/pss";
Naming.rebind(registryURL, rmi);
System.out.println("RMI server started...");
} catch (Exception e) {
System.out.println
("Server.main: an exception occurred: " + e.getMessage());
e.printStackTrace();
}
}
public static void startRegistry(int RMIPortNum) throws RemoteException {
try {
Registry registry = LocateRegistry.getRegistry(RMIPortNum);
registry.list();
}
catch (RemoteException e) {
Registry registry = LocateRegistry.createRegistry(RMIPortNum);
}
}
}
When I launch the server, I do:
sudo java -Djava.rmi.server.hostname=<outward IP> Server
Also, I've checked to make sure the port if forwarded correctly at the router.
Thanks Everyone,
vital_101