AddServerIntf.java
import java.rmi.*;
public interface AddServerIntf extends Remote
{
double add(double d1,double d2)throws RemoteException;
}
AddServerImpl.java
import java.rmi.*;
import java.rmi.server.*;
public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf
{
public AddServerImpl()throws RemoteException
{
}
public double add(double d1,double d2)
{
return d1+d2;
}
}
*AddClient.java
import java.rmi.*;
public class AddClient
{
public static void main (String args[])
{
try{
String addserverURL="rmi://"+args[0]+ "/AddServer";
AddServerIntf addserverintf=(AddServerIntf)Naming.lookup(addserverURL);
System.out.println("The first number is:"+args[1]);
double d1=Double.valueOf(args[1]).doubleValue();
System.out.println("the second number is:"+args[2]);
double d2=Double.valueOf(args[2]).doubleValue();
System.out.println("The sum is:"+addserverintf.add(d1,d2));
}
catch(Exception e)
{
System.out.println("Exception:"+e);
}
}
}
*AddServer.java
import java.net.*;
import java.rmi.*;
public class AddServer
{
public static void main(String args[])
{
try{
AddServerImpl addserverimpl=new AddServerImpl();
Naming.rebind("AddServer",addserverimpl);
}
catch(Exception e)
{
System.out.println("Exception"+e);
}
}
}
1.Compile al the files.(javac filename.java)
2.Create stub and skeleton for your AddServerImpl.java using the following command
rmic -vcompat AddServerImpl
3.Run the rmiregistry from bin of your jdk folder,leave it unclosed.
4.Run your server file with foolwing command:
java AddServer
5.Open new command prompt window,set the path and run your client code:
java AddClient 127.0.0.1 1 1
6.u should c the summed up value,here 127.0.0.1 is the local host(ur own system).
**If the program is not working set the CLASSPATH in the environmental variable:
Right click my computer->properties->advanced->Environment variable(at de bottome)
In the user variable click new type name as CLASSPATH and for value set u r path where ur java code resides.
Eg:c:\java\rmi


0 comments
Post a Comment