public interface RemoteInterface extends
java.rmi.Remote{ public java.util.Date askTime() throws java.rmi.RemoteException; public void tellTime(java.util.Date d) throws java.rmi.RemoteException; } |
public class RemoteObject extends
java.rmi.server.UnicastRemoteObject implements RemoteInterface{ public RemoteObject() throws java.rmi.RemoteException{ // Empty constructor } public java.util.Date askTime() throws java.rmi.RemoteException{ System.out.println("RemoteObject.askTime called" + new java.util.Date() + "\n"); return new java.util.Date(); } public void tellTime(java.util.Date d) throws java.rmi.RemoteException{ System.out.println("RemoteObject.tellTime called" + d + "\n"); } } |
public class Server{ public static void main(String[] args){ try{ System.setSecurityManager(new java.rmi.RMISecurityManager()); RemoteInterface v=new RemoteObject(); java.rmi.registry.LocateRegistry.createRegistry(5099); java.rmi.Naming.rebind("//:5099/count", v); }catch(java.rmi.UnknownHostException x){x.printStackTrace();} catch(java.rmi.RemoteException x){x.printStackTrace();} catch(java.net.MalformedURLException x){x.printStackTrace();} catch(Exception x){x.printStackTrace();} } } |
public class Client{ public static void main(String[] args){ RemoteInterface s=null; try{ s=(RemoteInterface)java.rmi.Naming.lookup("rmi://euclid.nmu.edu:5099/count"); s.tellTime(new java.util.Date()); System.out.println(s.askTime()); }catch (Exception x){x.printStackTrace();} } } |