Client/Server Technologies RPC and Java RMI: Lecture#5
Client/Server Technologies RPC and Java RMI: Lecture#5
Lecture#5
• The most common framework for newer protocols and for middleware
• Used both by operating systems and by applications
• DCOM, CORBA, Java RMI, etc., are just RPC systems
Remote Procedure Call (RPC)
• Fundamental idea: –
• Server process exports an interface of procedures or functions that can be
called by client programs
• similar to library API, class definitions, etc.
• Clients make local procedure/function calls
• As if directly linked with the server process
• Under the covers, procedure/function call is converted into a message
exchange with remote server process
Remote Procedure Call
RPC: A pair of Stubs
• A stub compiler reads the IDL declarations and produces two stub
functions for each server function
• Server-side and client-side
RPC Model (continued)
• Linking:–
• Server programmer implements the service’s functions and links with the
server-side stubs
• Client programmer implements the client program and links it with client-
side stubs
• Operation:–
• Stubs manage all of the details of remote communication between client and
server
RPC Stubs
• Java makes RMI (Remote Method Invocation) fairly easy, but there
are some extra steps
• To send a message to a remote “server object,”
• The “client object” has to find the object
• Do this by looking it up in a registry
• The client object then has to marshal the parameters (prepare them for
transmission)
• Java requires Serializable parameters
• The server object has to unmarshal its parameters, do its computation, and marshal its
response
• The client object has to unmarshal the response
Terminology
Therefore,
In order to use a remote object, the client must know its behavior
(interface), but does not need to know its implementation (class)
In order to provide an object, the server must know both its
interface (behavior) and its class (implementation)
In short,
The interface must be available to both client and server
The class of any transmitted object must be on both client and
server
The class whose method is being used should only be on the server
Classes
class HelloServer {
try {
}
catch (Exception e) {
}
}
}
The Hello World Client Program
class HelloClient {
HelloInterface hello;
String name = "rmi://localhost/HelloServer";
try {
hello = (HelloInterface)Naming.lookup(name);
System.out.println(hello.say());
}
catch (Exception e) {
System.out.println("HelloClient exception: " + e);
}
}
}
rmic
If all goes well, you should get the “Hello, World!” message
Summary
Trail: RMI
by Ann Wollrath and Jim Waldo
http://java.sun.com/docs/books/tutorial/rmi/index.html