Java RMI simple client-server application

Posted on 2004-12-01
Last Modified: 2012-05-05
I need to know how to write a simple java RMI server - client application to play a lottery. The player shuld select 6 distinct numbers in the range 1-100 and wins if any one of those numbers matches the single number generated at random on the server.
The lotto server receives and reads the list of numbers selected by the client, then it checks that the list is valid, if not, it return an error message and if yes, the lottery draw and see if the client has any winning numbers. The server then returns the result to the client.
Question by:chris_black23
    LVL 86

    Expert Comment

    We can't produce homework code. Break the problem down. Look for the Sun tutorials
    LVL 86

    Accepted Solution

    One thing you can do is to produce the random classes independently of the RMI stuff to begin with
    LVL 2

    Assisted Solution

    I would do as CEHJ says, you can go and create your "template" RMI classes which are standard no matter what your going to do. Look at Suns pages, once you have that then you can start adding the functionality you need.
    LVL 17

    Assisted Solution

    by:Dejan Pažin

    And dont forget: Using java 1.5, all the RMI stuff can be generated for you. Try it with IntelliJ IDEA, you can get a trial licence. All you need to do is, check: Compiler --> RMI Compiler --> Enable RMI stubs generation.

    The only thing you need to do is create an interface, which extends Remote, and implement it. And of course start the rmiregistry, register the object and then call the methods on it from the client. This is how you do it for the server side:

             Registry registry = LocateRegistry.createRegistry(portNo);
             registry.bind("NameForYourServerObject", yourServerObject);

    And then call it on the client:

             Registry registry = LocateRegistry.getRegistry("localhost", portNo);
             serverObject = (ServerObjectClass) registry.lookup("NameForYourServerObject");

    It really is that easy.
    LVL 92

    Assisted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now