RMI PROGRAM
Rmi interface:
import java.rmi.*;
public interface rminter extends Remote
{
public int add(int x,int y)throws RemoteException;
}
rmi server program:
import java.io.*;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
public class rmser extends UnicastRemoteObject implements rminter
{
public rmser()throws RemoteException
{
super();
}
public int add(int x,int y)throws RemoteException
{
return(x+y);
}
public static void main(String args[])
{
try
{
rmser m=new rmser();
Naming.rebind("rmser",m);
System.out.println("Server Started");
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Client program:
import java.io.*;
import java.rmi.*;
public class rmcli
{
public static void main(String args[])
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
try
{
String url="rmi://localhost/rmser";
rminter i=(rminter)Naming.lookup(url);
System.out.println("\n");
System.out.println("Enter the First number");
int a1=Integer.parseInt(in.readLine());
System.out.println("Enter the second number");
int a2=Integer.parseInt(in.readLine());
System.out.println("\n");
System.out.println("1.Addition");
int ch;
do
{
System.out.println("Enter ur choice");
ch=Integer.parseInt(in.readLine());
switch(ch)
{
case 1:
System.out.println("Addition:"+i.add(a1,a2));
break;
}
} while(ch<=2);
}
catch(Exception e){}
}
}
Server start screen:
Client Output Screen:
Strat registry
No comments:
Post a Comment