import java.rmi.*;
public interface readinterface
extends Remote
{
public int read()
throwsRemoteException;
}
import java.rmi.*;
import java.rmi.server.*;
import java.io.*;
public class readserver extends
UnicastRemoteObject implements readinterface
{
public
readserver()throwsRemoteException
{
}
public int read() throws
RemoteException
{
DataInputStream k=new
DataInputStream(System.in);
try
{
int r=Integer.parseInt(k.readLine());
return r;
}
catch(Exception e)
{
System.out.println("the io
exception raised in the read function"); }
return 1;
}
public static void main(String
agrs[])
{
try
{
readserver r1=new readserver();
Naming.rebind("ramu1",r1);
System.out.println("the ramu1
server started for reading");
}
catch(Exception e)
{
System.out.println("the exception
raised in the read server");
}}}
import java.rmi.*;
public interface addinterface extends
Remote
{
public int add(int x,int y) throws
RemoteException;
public int sub(int x,int y) throws
RemoteException;
}
import java.rmi.*;
import java.rmi.server.*;
import java.io.*;
public class addserver extends UnicastRemoteObject implements
addinterface
{
public addserver() throws
RemoteException
{}
public int add(int x,int y) throws RemoteException
{
return x+y;
}
public int sub(int x,int y) throws RemoteException
{
return x-y;
}
public static void main(String
args[])
{
try
{
addserver a=new addserver();
Naming.rebind("ramu2",a);
System.out.println(" the add
server ramu2 is also started");
}
catch(Exception e){}
}}
import java.rmi.*;
import java.rmi.server.*;
public class myclint
{
public static void main(String
args[])
{
try
{
readinterface r=
(readinterface)Naming.lookup("ramu1");
addinterface
a=(addinterface)Naming.lookup("ramu2");
int x=r.read();
System.out.println("this value
is obtained from server1"+x);
int y=r.read();
System.out.println("this value
is obtained from server1"+y);
int z=a.add(x,y);
System.out.println("\n this
result is obtained from the second server"+z);
}
catch(Exception e){}
}}
for creation of batchfile for the
above program run.bat
javac addinterface.java
javac addserver.java
javac readinterface.java
javac readserver.java
start rmiregistry
rmic addserver
rmic readserver
start
java addserver
start
java readserver
java myclint
కామెంట్లు లేవు:
కామెంట్ను పోస్ట్ చేయండి