0% found this document useful (0 votes)
77 views5 pages

Rmi Calculator Assigment

The document describes code for a remote method invocation (RMI) calculator application. It includes code for the Calculator interface defining remote add and sub methods, a CalculatorImpl class implementing the interface, an RmiServer class starting the RMI registry and exporting the CalculatorImpl object, and an RmiClient class looking up and calling the add method on the remote object. The client code successfully calls the add method and prints the result, showing the RMI application is running as intended.

Uploaded by

Wasib Hussain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views5 pages

Rmi Calculator Assigment

The document describes code for a remote method invocation (RMI) calculator application. It includes code for the Calculator interface defining remote add and sub methods, a CalculatorImpl class implementing the interface, an RmiServer class starting the RMI registry and exporting the CalculatorImpl object, and an RmiClient class looking up and calling the add method on the remote object. The client code successfully calls the add method and prints the result, showing the RMI application is running as intended.

Uploaded by

Wasib Hussain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Wasib Zameer Solangi

Roll no 2k18/swe/126
Distributed Systems

RMI Calculator Assignment


Calculator class codes

import java.rmi.*;
import java.rmi.server.*;

interface Calculator extends Remote {


int add(int a, int b) throws RemoteException ;
int sub(int a, int b) throws RemoteException ;
}

CalculatorImpil class codes


import java.rmi.*;
import java.rmi.server.*;
class CalculatorImpl implements Calculator
{

public int add(int a, int b) throws RemoteException


{
System.out.println("sum is ="+(a+b));
return (a+b) ;
}
public int sub(int a, int b) throws RemoteException
{

return (a-b);
}

RmiServer codes
import java.rmi.*;
import java.rmi.server.*;
class CalculatorServer{
public static void main (String args[]) throws RemoteException,
java.net.MalformedURLException{
CalculatorImpl cl = new CalculatorImpl();
UnicastRemoteObject.exportObject(cl);
Naming.rebind("CalculatorObject", cl);
System.out.println("RMI server Starteddd!!!");

}
}

RmiClient codes
import java.rmi.*;
public class RmiClient {
public static void main (String args[])
throws RemoteException, NotBoundException, java.net.MalformedURLException{
Calculator ob= (Calculator)Naming.lookup("CalculatorObject");
int add=ob.add(2,4);
System.out.println("Sum is : "+add);
}
}

● Compiled all codes


● Compiled with rmic
● Started rmi registry
Server is running

Client side is also running


Collective snapshot

You might also like