Results 1 to 4 of 4
  1. #1
    clapton is offline Member
    Join Date
    Feb 2012
    Posts
    5
    Rep Power
    0

    Default help for java rmi

    Hi.
    I wrote this program claculator java rmi.but not implemented.
    you can help me?
    Java Code:
        import java.rmi.Remote;
        import java.rmi.RemoteException;
         
        public interface calculator extends Remote {
         
        public long add(long a, long b)
        throws RemoteException;
         
        public long sub(long a, long b)
        throws RemoteException;
         
        public long mul(long a, long b)
        throws RemoteException;
         
        public long div(long a, long b)
        throws RemoteException;
        }
    Java Code:
        import java.rmi.Naming;
        import java.rmi.RemoteException;
        import java.rmi.RMISecurityManager;
        import java.rmi.server.UnicastRemoteObject;
         
        public class calculatorServer extends UnicastRemoteObject implements calculator {
        public calculatorServer () throws RemoteException {
        super();
        }
        public long add(long a, long b) {
        return a + b;
        }
        public long sub(long a, long b) {
        return a * b;
        }
        public long mul(long a, long b) {
        return a - b;
        }
        public long div(long a, long b) {
        return a / b;
        }
        public static void main(String args[]) {
         
        try {
        Calculatorserver clapton = new Calculatorserver();
        Naming.rebind("rmi://localhost:1099/CalculatorService", clapton);
        } catch (Exception e) {
        System.out.println("Trouble: " + e);
        }
        }
         
         
        }
    Java Code:
        import java.rmi.Naming;
        import java.rmi.RemoteException;
         
        public class CalculatorClient {
         
        public static void main(String[] args) {
        try {
        Calculator clapton = (Calculator)
        Naming.lookup(
        "rmi://localhost
        /CalculatorService");
        System.out.println( c.sub(4, 3) );
        System.out.println( c.add(4, 5) );
        System.out.println( c.mul(3, 6) );
        System.out.println( c.div(9, 3) );
        }
        catch (Exception e) {
        System.out.println("Trouble: " + e);
        }
        }
        }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,123
    Rep Power
    20

    Default Re: help for java rmi

    Help with what exactly?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    clapton is offline Member
    Join Date
    Feb 2012
    Posts
    5
    Rep Power
    0

    Default Re: help for java rmi

    i can't run this program.it is not work.you can run this program?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,123
    Rep Power
    20

    Default Re: help for java rmi

    I'm not even going to try.

    You need to tell us what the problem is...and "it doesn't work" is not a good answer.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •