DS Experiment no 2

Aim - Implementation of RMI using java


Client.java
import java.rmi.*;
public class MyClient{
public static void main(String args[]){
try{
Adder stub=(Adder)Naming.lookup("rmi://localhost:5000/sonoo");
int a=34;
int b=4;
System.out.println("Value of A: "+a+"\nValue of B: "+b);
System.out.println("Addition of A and B: "+stub.add(a,b));
System.out.println("Subsctraction of A and B: "+stub.sub(a,b));
System.out.println("Mul of A and B: "+stub.mul(a,b));
System.out.println("Divion of A and B: "+stub.div(a,b));
}catch(Exception e){System.out.println(e); } } }

Server.java

import java.rmi.*;
import java.rmi.registry.*;
public class MyServer{
public static void main(String args[]){
try{
Adder stub=new AdderRemote();
Naming.rebind("rmi://localhost:5000/sonoo",stub);
}catch(Exception e){System.out.println(e);}}}

Interface adder.java

import java.rmi.*;
public interface Adder extends Remote{

public int add(int x,int y)throws RemoteException;
public int sub(int x,int y)throws RemoteException;
public int mul(int x,int y)throws RemoteException;
public int div(int x,int y)throws RemoteException;
}

AdderRemote.java

import java.rmi.*;
import java.rmi.server.*;
public class AdderRemote extends UnicastRemoteObject implements Adder{
AdderRemote()throws RemoteException{
super();}
public int add(int x,int y){
System.out.println("Value of a: "+x);
System.out.println("Value of a: "+y);
int add=x+y;
System.out.println("Addition: ");
return add;}
public int sub(int x,int y){
int sub=x-y;
System.out.println("Substraction: ");
return sub;}
public int mul(int x,int y){
int mul=x*y;
System.out.println("Multiplication: ");
return mul;}
public int div(int x,int y){
int div=x/y;
System.out.println("Division: ");
return div;}}

OUTPUT:

Client Side:

C:\Users\mgmcet@it\Desktop\New Folder\1>java MyClient
Value of A: 34
Value of B: 4
Addition of A and B: 38
Subsctraction of A and B: 30
Mul of A and B: 136
Divion of A and B: 8

Interface:
C:\Users\mgmcet@it\Desktop\New Folder\1>rmiregistry 5000

Server Side:

C:\Users\mgmcet@it\Desktop\New Folder\1>java MyServer
Value of a: 34
Value of a: 4
Addition:
Substraction:
Multiplication:
Division:



click here to download
DS Experiment no 2 DS Experiment no 2 Reviewed by Akshay Salve on 12:37 PM Rating: 5

No comments:

Powered by Blogger.