ADDSERVERINTF.JAVA
import java.rmi.*;
public interface AddServerIntf extends Remote
{
public double add(double d1,double d2) throws RemoteException;
}
ADDSERVERIMP.JAVA
import java.rmi.*;
import java.rmi.server.*;
public class AddServerImp extends UnicastRemoteObject implements AddServerIntf
{
public AddServerImp() throws RemoteException
{
}
public double add(double d1,double d2) throws RemoteException
{
return d1+d2;
}
}
ADDSERVER.JAVA
import java.net.*;
import java.rmi.*;
public class AddServer
{
public static void main(String args[])
{
try
{
AddServerImp a1=new AddServerImp();
Naming.rebind("AddServer",a1);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
ADDCLIENT.JAVA
import java.net.*;
import java.rmi.*;
public class AddClient
{
public static void main(String args[])
{
try
{
String u1="rmi://"+args[0]+"/AddServer";
AddServerIntf a1=(AddServerIntf)Naming.lookup(u1);
System.out.println("1st no."+args[1]);
System.out.println("2nd no."+args[2]);
double d1=Double.parseDouble(args[1]);
double d2=Double.parseDouble(args[2]);
System.out.println("the Sum is "+a1.add(d1,d2));
}
catch(Exception e)
{
System.out.println(e);
}
}
}
No comments:
Post a Comment