/* Implementation of Remote Method Invocation ( RMI ) */
// RMIServerInter.java : A Simple RMI Server Interface Program
import java.rmi.*;
public interface RMIServerInter extends Remote
{
public double add(double d1,double d2) throws RemoteException;
public double sub(double d1,double d2) throws RemoteException;
public double mul(double d1,double d2) throws RemoteException;
public double div(double d1,double d2) throws RemoteException;
}
// RMIServerImpl.java : A Simple RMI Server Implementation Program
import java.rmi.*;
import java.rmi.server.*;
public class RMIServerImpl extends UnicastRemoteObject
implements RMIServerInter
{
public RMIServerImpl() throws Exception
{
}
public double add(double d1,double d2) throws RemoteException
{
return d1+d2;
}
public double sub(double d1,double d2) throws RemoteException
{
return d1-d2;
}
public double mul(double d1,double d2) throws RemoteException
{
return d1*d2;
}
public double div(double d1,double d2) throws RemoteException
{
return d1/d2;
}
}
// RMIServer.java : A Simple RMI Server Program
import java.rmi.*;
import java.net.*;
public class RMIServer
{
public static void main(String args[])
{
try
{
RMIServerImpl ad=new RMIServerImpl();
Naming.rebind("RMIServer",ad);
}
catch(Exception e)
{
System.out.println("Error ... " + e.getMessage());
}
}
}
// RMIClient.java : A Simple RMI Client Program
import java.rmi.*;
import java.net.*;
public class RMIClient
{
public static void main(String args[])
{
try
{
String serverurl="rmi://localhost/RMIServer";
RMIServerInter ad=(RMIServerInter) Naming.lookup(serverurl);
System.out.println("The Sum of the values is : "+ ad.add(50,20));
System.out.println("The Difference of the values is : "+ad.sub(40,20));
System.out.println("The Product of the values is : "+ ad.mul(25,20));
System.out.println("The Divition of the values is : "+ ad.div(200,20));
}
catch(Exception e)
{
System.out.println("Error ... " + e.getMessage());
}
}
}
OUTPUT :
RMIServerInter.java :
javac RMIServerInter.java
RMIServerImpl.java :
javac RMIServerImpl.java
RMIServer.java :
javac RMIServer.java
RMIClient.java :
javac RMIClient.java
Start RMI Registry :
start rmiregistry
RMIServerImpl.class:
rmic RMIServerImpl
javac RMIClient.java
javac RMIServer.java
javac RMIServerImpl.java
javac RMIServerInter.java
RMIServer.java :
java RMIServer
RMIClient.java :
java RMIClient
The Sum of the values is : 70.0
The Difference of the values is : 20.0
The Product of the values is : 500.0
The Divition of the values is : 10.0
1 comment:
its saying error connection refused to connect to host
Post a Comment