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:
• Write a program to play Lotto according to the rules above.
• Understand the invocation of methods on remote objects.
• Understand the production of distributed Java objects.
Summary of the Work
You will have to:
• Define the remote methods to allow the client to send the numbers to the server.
• Implement these methods as a remote object.
• Write a client to invoke the remote methods.
• Use the rmic program to produce a stub and a skeleton.
• 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):
• If not, return an error message to the client.
• If yes, make the lottery draw and see if the client has any winning
numbers. Return the result to the client.
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 numbers.
2. Derive the class from the UnicastRemoteObject class
3. Create a LottoServer class with a method that creates a object. Register 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. 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.
5 freelancers are bidding on average £74 for this job
I have already done [url removed, login to view] check the PMKindly see the attached file it might help you because i have already implemented a Student Server Score Application in Java Using RMI.