img
the remote machine. That is, an object passed as an argument to a remote method call must
be serialized and sent to the remote machine. Recall from Chapter 19 that the serialization
facilities also recursively process all referenced objects.
If a response must be returned to the client, the process works in reverse. Note that the
serialization and deserialization facilities are also used if objects are returned to a client.
To generate a stub, you use a tool called the RMI compiler, which is invoked from the
command line, as shown here:
rmic AddServerImpl
This command generates the file AddServerImpl_Stub.class. When using rmic, be sure that
CLASSPATH is set to include the current directory.
Step Three: Install Files on the Client and Ser ver Machines
Copy AddClient.class, AddServerImpl_Stub.class, and AddServerIntf.class to a directory
on the client machine. Copy AddServerIntf.class, AddServerImpl.class, AddServerImpl_
Stub.class, and AddServer.class to a directory on the server machine.
NOTE  RMI has techniques for dynamic class loading, but they are not used by the example at
OTE
hand. Instead, all of the files that are used by the client and server applications must be installed
manually on those machines.
Step Four: Start the RMI Registr y on the Ser ver Machine
Java SE 6 provides a program called rmiregistry, which executes on the server machine. It
maps names to object references. First, check that the CLASSPATH environment variable
includes the directory in which your files are located. Then, start the RMI Registry from the
command line, as shown here:
start rmiregistry
When this command returns, you should see that a new window has been created. You
need to leave this window open until you are done experimenting with the RMI example.
Step Five: Start the Ser ver
The server code is started from the command line, as shown here:
java AddServer
Recall that the AddServer code instantiates AddServerImpl and registers that object with
the name "AddServer".
Step Six: Start the Client
The AddClient software requires three arguments: the name or IP address of the server
machine and the two numbers that are to be summed together. You may invoke it from
the command line by using one of the two formats shown here:
java AddClient server1 8 9
java AddClient 11.12.13.14 8 9
In the first line, the name of the server is provided. The second line uses its IP address
(11.12.13.14).
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home