LP 1
CLIENT
import java.rmi.*;
import java.util.*;
public class client {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
try {
String serverURL="rmi://localhost/server";
serverinterface Serverinterface = (serverinterface)Naming.lookup(serverURL);
System.out.println("Enter first Number :");
double num1 =sc.nextDouble();
System.out.println("Enter 2nd number:");
double num2 =sc.nextDouble();
System.out.println("Fisrt Number is :" + num1);
System.out.println("Fisrt Number is :" + num2);
System.out.println("*************Result************");
System.out.println("Addition is " + serverinterface.addition(num1,num2));
System.out.println("substraction is " + serverinterface.Sub(num1,num2));
System.out.println("multiplication is " + serverinterface.Multi(num1,num2));
System.out.println("division is " + serverinterface.Divi(num1,num2));
} catch (Exception e) {
System.out.println("Exception Occured at client"+ e.getMessage());
}
}
}
SERVER
import java.rmi.*;
public class server {
public static void main(String[] args) {
try {
serverimplementation Serverimplementation = new serverimplementation();
Naming.rebind("server", Serverimplementation);
System.out.println("Server Started");
} catch (Exception e) {
System.out.println("Exception occured at server" + e.getMessage());
}
}
}
SERVER INTERFACE
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.*;
interface serverinterface extends Remote{
public static double addition(double num1,double num2) throws RemoteException {
return num1+num2;
}
public static double Sub(double num1,double num2) throws RemoteException {
return num1-num2;
}
public static double Multi(double num1,double num2) throws RemoteException {
return num1*num2;
}
public static double Divi(double num1,double num2) throws RemoteException {
return num1/num2;
}
}
SERVER IMPLEMENTATION
import java.rmi.*;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.server.*;
public class serverimplementation extends UnicastRemoteObject implements serverinterface {
public serverimplementation()throws RemoteException{
}
public double addition(double num1,double num2) throws RemoteException{
return num1 + num2 ;
}
public double Sub(double num1,double num2) throws RemoteException{
return num1 - num2 ;
}
public double Multi(double num1,double num2) throws RemoteException{
return num1 * num2 ;
}
public double Divi(double num1,double num2) throws RemoteException{
if (num2 != 0) {
return num1 / num2 ;
}
else{
System.out.println("Cant divide the number");
}
return num1/num2;
}
}
Comments
Post a Comment