// remote interface - // extends java.rmi.Remote // each method throws java.rmi.RemoteException // distributed server - // extends java.rmi.server.UnicastRemoteObject // implements remote interface // constructor throws java.rmi.RemoteException // use rebind() to register a physical instance under a logical name // distributed client - // use lookup() with a logical name to retrieve a physical proxy interface RIUpper extends java.rmi.Remote { String toUpper( String in ) throws java.rmi.RemoteException; } public class UpperServer extends java.rmi.server.UnicastRemoteObject implements RIUpper { private int count = 0; public UpperServer() throws java.rmi.RemoteException { super(); } public String toUpper( String in ) { System.out.println( "request " + ++count + " - " + in ); return in.toUpperCase(); } public static void main( String[] args ) { try { java.rmi.Naming.rebind( "UpperServerName", new UpperServer() ); } catch (java.net.MalformedURLException ex) { ex.printStackTrace(); } catch (java.rmi.RemoteException ex) { ex.printStackTrace(); } System.out.println( "UpperServer bound in rmiregistry" ); } } public class UpperClient { public static void main( String[] args ) { try { RIUpper converter = (RIUpper) java.rmi.Naming.lookup( "UpperServerName" ); java.io.BufferedReader rdr = new java.io.BufferedReader( new java.io.InputStreamReader( System.in )); String str; while (true) { System.out.print( "Input text ---- " ); str = rdr.readLine(); if (str.equals("quit")) break; System.out.println( " Response --- " + converter.toUpper( str ) ); } } catch (java.rmi.NotBoundException ex) { ex.printStackTrace(); } catch (java.rmi.RemoteException ex) { ex.printStackTrace(); } catch (java.io.IOException ex) { ex.printStackTrace(); } } } // D:\j2ee> javac UpperServer.java // D:\j2ee> rmic -v1.2 UpperServer // D:\j2ee> start rmiregistry // D:\j2ee> java UpperServer // UpperServer bound in rmiregistry // request 1 - The quick, brown, fox - jumped ... // request 2 - Over the _lazy_ dog. // request 3 - Now, is - the time ... // request 4 - For *all* good men. // D:\j2ee> javac UpperClient.java // D:\j2ee> java UpperClient // Input text ---- The quick, brown, fox - jumped ... // Response --- THE QUICK, BROWN, FOX - JUMPED ... // Input text ---- Over the _lazy_ dog. // Response --- OVER THE _LAZY_ DOG. // Input text ---- quit // D:\j2ee> java UpperClient // Input text ---- Now, is - the time ... // Response --- NOW, IS - THE TIME ... // Input text ---- For *all* good men. // Response --- FOR *ALL* GOOD MEN. // Input text ---- quit