In this assignment, you will use Java RMI to write a simple client-server application to play
a Lottery. The player should select 6 distinct numbers in the range 1-50 and wins if any one
of those numbers matches the single number generated at random on the server.
The objectives of this coursework are to:
&acirc;€¢ Write a program to play Lotto according to the rules above.
&acirc;€¢ Understand the invocation of methods on remote objects.
&acirc;€¢ Understand the production of distributed Java objects.
Summary of the Work
You will have to:
&acirc;€¢ Define the remote methods to allow the client to send the numbers to the server.
&acirc;€¢ Implement these methods as a remote object.
&acirc;€¢ Write a client to invoke the remote methods.
&acirc;€¢ Use the rmic program to produce a stub and a skeleton.
&acirc;€¢ Use the rmiregistry tool to register the server.
Defining the Interface
In this coursework, firstly you define the server methods. The Lotto server receives and
reads the list of numbers selected by the client. Then it checks that this list is valid
(distinct numbers in the range 1-50):
&acirc;€¢ If not, return an error message to the client.
&acirc;€¢ If yes, make the lottery draw and see if the client has any winning
numbers. Return the result to the client. 2
The server is comprised of an interface and a class. The interface provides the
definition for the methods that can be called from the client. Essentially the interface
defines the client's view of the remote object. The class provides the
implementation. Define these methods in a Java LottoInfo interface. Derive the
interface from the Remote class or from [url removed, login to view] interface (The
interface must extend from java.rmi.Remote. All the method declarations must
include the throws [url removed, login to view] clause).
Implementing the Remote Objects on the Server
Write the LottoInfoImpl class that implements the LottoInfo interface and the
LottoServer class that creates an object and registers it on the server.
1. Write the LottoInfoImpl class that contains the actual methods to receive the
2. Derive the class from the UnicastRemoteObject class
3. Create a LottoServer class with a method that creates a [url removed, login to view] this
object with the RMI remote object registry, name and bind it to a port using the
Naming class and the rebind() method.
Programming the Client
Produce the LottoClient class that locates the server and invokes the remote methods.
The command to start the client will be
$ java LottoClient rmi://machine/remote_object
Where the URL refers to the registry(usually on the same machine that the server runs
on, probably localhost).
Retrieve the remote object using the Naming class, by passing the use of the registry to
the lookup() method. Then make the remote method call on this object.
Producing the Distributed Objects
Finally, compile and run the distributed objects.
1. Compile all the classes you have written.
2. Your RMI java programs are only a part of the application. It uses two other pieces
of code called the stub and the skeleton. These reformat the method parameters and
encapsulate them into a RMI data unit. This process is called marshalling. Run the
command rmic LottoInfoImpl to generate the stub and the skeleton. 3
3. Launch the registry rmiregistry. Be sure to run the registry in the RMI server
directory that contains the stub and skeleton.
4. Run the server and the client on a same machine and directory. Then try to run the
client and the server on two different machines.
You should submit your code both on paper and on disk (hand in the assignment to
the undergraduate office in the normal way with a CD containing only the *.java
Write a report on the design and implementation of your solution and answers, showing
code and results: (i) a class diagram outlining the class structure for your proposed
solution. (ii) a set of summary tables desc