RMI using JAVA

Practical : 5
Subject : Advanced Java
Aim : Write RMI application where client supplies two numbers and server response by summing it. Provide your custom security policy for this application.


AddI.java Code:
--------------------------------------------------------------------------------
import java.rmi.Remote;
public interface AddI extends Remote
{
public int add(int x,int y) throws Exception;
}
--------------------------------------------------------------------------------
AddC.java Code:
--------------------------------------------------------------------------------
import java.rmi.*;
import java.rmi.server.*;
public class AddC extends UnicastRemoteObject implements AddI
{
AddC() throws Exception
{
super();
}
public int add(int x,int y)
{
return x+y;
}

}
--------------------------------------------------------------------------------
Server.java Code:

--------------------------------------------------------------------------------
import java.rmi.*;
public class Server
{
public static void main(String args[]) throws Exception
{
AddI obj= new AddC();
Naming.rebind("Adder",obj);
System.out.println("Server Started");
}

}
--------------------------------------------------------------------------------
Client.java Code:


--------------------------------------------------------------------------------
import java.rmi.*;
import java.util.Scanner;

public class Client
{
public static void main(String args[]) throws Exception
{
AddI obj=(AddI)Naming.lookup("Adder");
Scanner scan=new Scanner(System.in);
System.out.println("Enter 2 numbers to do addition:");
int a=scan.nextInt();
int b=scan.nextInt();
int sum=obj.add(a,b);
System.out.println("Addition :\t" + sum);
}

}
--------------------------------------------------------------------------------

Output:
Commands

Server

Client

Previous
Next Post »

2 comments

Write comments

Ads