The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.rmi  [3 examples]

e505. Looking Up a Portable Remote Object and Invoking a Method

    import javax.naming.*;
    import java.rmi.RemoteException;
    import javax.rmi.PortableRemoteObject;
    
    
    // JRMP: name = "rmi://localhost/RObjectServer";
    // IIOP: name = "iiop://localhost/RObjectServer";
    try {
        // Look up remote object
        Object obj = new InitialContext().lookup(name);
    
        // Cast to the appropriate type
        RObject robj = (RObject)PortableRemoteObject.narrow(obj, RObject.class);
    
        // Invoke method on remote object
        robj.aMethod();
    } catch (NamingException e) {
    } catch (RemoteException e) {
    }

 Related Examples
e503. Starting the Name Server
e504. Defining and Exporting a Portable Remote Object


© 2002 Addison-Wesley.