import java.rmi.*; // Remote, RemoteException import javax.rmi.*; // PortableRemoteObject import javax.naming.*; // InitialContext interface RICase extends Remote { String convert( String in ) throws RemoteException; } public class JndiCaseServer extends PortableRemoteObject implements RICase { public JndiCaseServer() throws RemoteException { } public String convert( String in ) { System.out.println( "JndiCaseServer.convert() - " + in ); return in.toUpperCase(); } public static void main( String[] args ) { try { java.util.Hashtable props = new java.util.Hashtable(); props.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory" ); // without the next line, received the following error: // javax.naming.CommunicationException: Cannot connect to ORB. // Root exception is org.omg.CORBA.COMM_FAILURE props.put( Context.PROVIDER_URL, "iiop://localhost:1100" ); InitialContext ic = new InitialContext( props ); ic.rebind( "CaseServer", new JndiCaseServer() ); System.out.println( "JndiCaseServer bound in JNDI" ); } catch (NamingException ex ) { ex.printStackTrace(); } catch (RemoteException ex ) { ex.printStackTrace(); } } } import java.rmi.*; // RemoteException import javax.rmi.*; // PortableRemoteObject import javax.naming.*; // InitialContext public class JndiCaseClient { public static void main( String[] args ) { try { java.util.Hashtable props = new java.util.Hashtable(); props.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory" ); props.put( Context.PROVIDER_URL, "iiop://123.0.0.456:1100" ); InitialContext ic = new InitialContext( props ); Object object = ic.lookup( "CaseServer" ); RICase toUpper = (RICase) PortableRemoteObject.narrow( object, RICase.class ); String one = "Now is _the_ time -"; System.out.println( "sent ----- " + one ); System.out.println( "received - " + toUpper.convert( one ) ); String two = "For **all** good men,"; System.out.println( "sent ----- " + two ); System.out.println( "received - " + toUpper.convert( two ) ); } catch (NamingException ex) { ex.printStackTrace(); } catch (RemoteException ex) { ex.printStackTrace(); } } } // D:\> j2ee -verbose // // D:\j2ee\demos> javac JndiCaseServer.java // D:\j2ee\demos> java JndiCaseServer // JndiCaseServer bound in JNDI // JndiCaseServer.convert() - Now is _the_ time - // JndiCaseServer.convert() - For **all** good men, // // D:\j2ee\demos> javac JndiCaseClient.java // D:\j2ee\demos> java JndiCaseClient // sent ----- Now is _the_ time - // received - NOW IS _THE_ TIME - // sent ----- For **all** good men, // received - FOR **ALL** GOOD MEN,