Java Reference
In-Depth Information
granted the permissions listed in the policy file. In that way, a rather permissive
policy file still will not open up your machine to attacks from unknown codebases.
Almost everything is ready now, except for the codebase and a way for the client
to download the needed stub classes from the server. Typically, the download is
provided with a web server using an http: URL as the codebase. Setting up a
web server such as Apache is not particularly difficult, but is beyond the scope of
this topic [see 2]. Instead, we package all the needed class files, including the stubs
this time, into a clientall.jar file that must be copied to the client machine.
That way, the client will find all its needed classes in its local CLASSPATH and
will not need to consult the codebase at all. The server still needs to provide a
valid file: URL codebase so the RMI registry can find the stubs it needs.
To summarize the steps required for running on two machines:
1. Make the source code changes above to specify the actual server hostname instead of
localhost .
2. Modify the server.policy file to permit connections by the server host and the
client host.
3. Build a JAR file containing the classes needed by the client, including stubs
4. Copy that JAR file to the client machine.
5. Start rmiregistry on the server machine using the port number hard coded into the
client and server source codes.
6. Start the server application.
7. Run the client application.
Note that for this JAR file, one can explicitly list the .class files needed by the
client. For convenience, one can also make a JAR file containing everything in the
build/classes directory, including server-side classes at the cost of having
to transfer a slightly larger JAR file than actually needed on the client machine.
The Web Course contains an rmi18-2 directory that has these changes as
well as the needed build and run scripts. The reader will, of course, have to
change myserver.somehwere.com and client.somewhere.com to the
proper host names.
18.8 Conclusion
This completes our simple RMI example. It may not have sounded so simple,
since the description was rather long and detailed. As one creates more realistic
RMI applications, one will realize that this truly was a simple example. However,
other applications are just extensions of the skills learned here. The only critical
aspect of RMI not demonstrated here is the use of remote objects as method
call parameters and the associated transfer of client-side bytecodes to the server.
Doing so is a simple extension of what was learned. There are also examples to be
found in the online Java documentation. Before developing a complete example
that demonstrates the client/server simulation architecture described in Chapters
Search WWH ::




Custom Search