Beruflich Dokumente
Kultur Dokumente
DEPARTMENT OF CSE
211416104185
BASIC CALCULATOR
CalcInf.java:
CalcImpl.java:
// Implement Remote behavior--CalcImpl.java
import java.rmi.*;
import java.rmi.server.*;
CalcServer.java:
// Server that names the service implemented--CalcServer.java
import java.rmi.*;
public class CalcServer
{
public static void main(String args[])
{
try {
CalcInf C = new CalcImpl();
Naming.rebind("CalcService", C);
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
CalcClient.java:
// Client that invokes remote host methods--CalcClient.java
import java.rmi.*;
import java.net.*;
public class CalcClient
{
public static void main(String[] args) throws Exception
{
try {
CalcInf C = (CalcInf) Naming.lookup("rmi://" +
args[0] + "/CalcService");
int a, b;
if (args.length != 3)
{
System.out.println("Usage: java CalcClient
<remoteip> <operand1> <operand2>");
System.exit(-1);
}
a = Integer.parseInt(args[1]);
b = Integer.parseInt(args[2]);
System.out.println( "\nBasic Remote Calc\n" );
System.out.println("Summation : " + C.add(a, b));
System.out.println("Difference : " + C.sub(a, b));
System.out.println("Product : " + C.mul(a, b));
System.out.println("Quotient : " + C.div(a, b));
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF CSE
211416104185
System.out.println("Remainder : " + C.rem(a, b));
}
catch (Exception E) {
System.out.println(E.getMessage());
}
}
}
OUTPUT:
SERVER:
z:\>javac CalcInf.java
CalcServer.java z:\>javac
z:\>start rmiregistry
z:\>java CalcServer
CLIENT:
Summation : 14
Difference :2
Product : 48
Quotient :0
Remainder :6