CS 542

Purpose

From this example you will learn about:

The objective is to make you familiar about programming with Java RMI.

Description

You will develop a simple Java RMI application, including three servers and a client. The servers run on remote machines and are registered in an RMI registry on those machines. A window should pop up when each server comes up declaring that the server is up.

You shall write the client as a Java applet. It provides a simple GUI: it contains two buttons and two text fields. The text fields are there to enter the server name and the host name on which the server is running. There is one `Exchange' button and one `Reset' button. Upon clicking the `Exchange' button, the server and the client should exchange a message. The message received at each end should be displayed in a new window. Clicking `Reset' clears the text fields.

On-line Help

Please read on-line document Java Remote Method Invocation (RMI) to learn about Java RMI programming. To learn to write a Java applet, you may want to read on-line document The Java Tutorial, in particular, the part 'Writing Applets'.

Guidelines


For example: To start the server, run

java -Djava.rmi.server.codebase=file:/.xinuserver/u56/username/public_html/myclasses/
-Djava.security.policy=$HOME/mysrc/policy examples.hello.HelloImpl

or

java -Djava.rmi.server.codebase=file:/homes/username/public_html/myclasses/
-Djava.security.policy=$HOME/mysrc/policy examples.hello.HelloImpl


 Naming.rebind("//myhost/HelloServer", obj);

 and

obj = (Hello)Naming.lookup("//myhost/HelloServer");

 myhost should be the host where you run your rmiregistry and server, such as xinu1.cs.purdue.edu, etc.

Note: In the client code you should not use

obj = (Hello)Naming.lookup("//" + getCodeBase().getHost() + "/HelloServer");

because this would give the name of the host from which the applet is downloaded, which would not be the host on which your server is running, unless you run appletviewer later on the same machine to view the applet.
 


 

 
 
 

You could use appletviewer in the following way:


appletviewer file:/homes/username/hello.html &