I am writing an application using Java RMI. I have already created the client and server. However, I am using localhost only. I want to be able to use a domain name for the client to contact the server. I have already registered a domain name: hotel.ddns.net. I wish to be able to keep it inside a personal network, and nothing to do with port forwarding or so. The client and the server are found on different computers. I have been looking for solutions but these are not directly related to my question. Could you guys help me since I am still new to this?
Here is my client code:
package Hotel_;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java_rmi.java_rmi_interface;
public class ClientRMI {
public java_rmi_interface connectToServer() throws NotBoundException{
try{
Registry myregistry = LocateRegistry.getRegistry("127.0.0.1",1099);
java_rmi_interface myinterface = (java_rmi_interface)myregistry.lookup("bookingServer");
System.out.println("client reaaaaaaady");
return myinterface;
}catch(RemoteException e){
e.printStackTrace();
}
return null;
}
}
here is my code for the server
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
public class ServerRMI {
public static void main(String[] args){
try{
//Timer timer = new Timer();
//timer.deletefunc();
Registry myregitry = LocateRegistry.createRegistry(1099);//create a registry that can be
accessed on this port
QueryCentre qs = new QueryCentre();//an instance of QueryCenter where remote methods are
found
Naming.rebind("bookingServer", qs);//naming the server and passing the class where remote
methods are found
System.out.println("server ready and waitiiiinnnggg!!!!!");
}catch(RemoteException | MalformedURLException e){
e.printStackTrace();
}
}
}
If you are working entirely within a personal network with private IP addresses (i.e. 192.168.x.x) then DDNS will do nothing for you. It is intended to work with external, routable addresses only.
You have a few choices, from most complex to least complex they are:
I strongly recommend #3 for your simple setup.