0% found this document useful (0 votes)
19 views6 pages

Ex 8

Uploaded by

lenskart05
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)
19 views6 pages

Ex 8

Uploaded by

lenskart05
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/ 6

CS22511– COMPUTER NETWORKS LABORATORY

EX.NO:8

DATE:

REMOTE METHOD INVOCATION(RMI)

AIM:
To implement Remote Method Invocation with simple calculator application.

ALGORITHM:
1. Start.
2. Create a remote interface.
3. Provide the implementation of remote interface.
4. Compile the implementation class and create the stub and skeleton object using RMIC
tool.
5. Start the registry service by RMI registry tool.
6. Create and start remote application(server).
7. Create and start client application.
8. Stop.

SOURCE CODE:
calculator:
public interface calculator extends java.rmi.Remote
{
public long add(long a,long b) throws java.rmi.RemoteException ;
public long sub(long a,long b) throws java.rmi.RemoteException ;
public long mul(long a,long b) throws java.rmi.RemoteException ;
public long div(long a,long b) throws java.rmi.RemoteException ;
}
calc_impl :
public class calc_imp extends java.rmi.server.UnicastRemoteObject implements calculator
{
public calc_imp() throws java.rmi.RemoteException
{
super();
}
public long add(long a,long b) throws java.rmi.RemoteException
{
return a+b;
}
public long sub(long a,long b) throws java.rmi.RemoteException

REGNO:2127220501132 PAGE NO:


{
return a-b;
}
public long mul(long a,long b) throws java.rmi.RemoteException
{
return a*b;
}
public long div(long a,long b) throws java.rmi.RemoteException
{
return a/b;
}
}
calc_server :
import java.rmi.Naming;
public class calc_server
{
public calc_server()
{
try
{
calculator c=new calc_imp();
Naming.rebind("rmi://localhost:1099/CalculatorService",c);
}
catch(Exception e)
{
System.out.println("Trouble : "+e);
}
}
public static void main(String args[])
{
new calc_server();
}
}
calc_client :
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
public class calc_client
{
public static void main(String[] args)
{
try
{
calculator c=(calculator)Naming.lookup("rmi://localhost/CalculatorService");
System.out.println(c.sub(4,3));
System.out.println(c.add(4,5));
REGNO:2127220501132 PAGE NO:
System.out.println(c.mul(3,6));
System.out.println(c.div(9,3));
}
catch(Exception e){
System.out.println(e);
} }}

OUTPUT:

REGNO:2127220501132 PAGE NO:


RESULT:
Thus, the program to implement Remote Method Invocation with simple calculator application is
executed and output is verified successfully

REGNO:2127220501132 PAGE NO:


REGNO:2127220501132 PAGE NO:
REGNO:2127220501132 PAGE NO:

You might also like