Remote Method Invocation [RMI]
allows object in one machine to use method in another machine
one method of creating distributed application
Layers in RMI
Stub/Skeleton Layer
Remote Reference Layer
Transport Layer
Client Server
Stub Skeleton
RRL RRL
Transport Layer Transport Layer
Example program to find the sum of 2 numbers using rmi
inter.java
import java.rmi.*;
public interface inter extends Remote
{
public void getdata(int m,int n) throws RemoteException;
int adddata() throws RemoteException;
}
server.java
import java.rmi.*;
import java.rmi.server.*;
public class server extends UnicastRemoteObject implements inter
{
int x,y;
public server() throws RemoteException
{
}
public int adddata() throws RemoteException
{
return x+y;
}
public void getdata(int m, int n) throws RemoteException
{
x=m; y=n;
}
public static void main(String arg[])
{
try
{
server s = new server();
Naming.rebind("Addserver",s);
}
catch(Exception e)
{
System.out.println("can not bund the name " + e);
}
}
}
client.java
import java.rmi.*;
public class client
{
public static void main(String arg[ ])
{
try
{
int a = Integer.parseInt(arg[1]);
int b = Integer.parseInt(arg[2]);
int result;
inter i = (inter) Naming.lookup("rmi://" + arg[0] +
"/Addserver");
System.out.println("client");
i.getdata(a,b);
result = i.adddata();
System.out.println(result);
}
catch(Exception e)
{
System.out.println("can not connect with server " + e);
}
}
}
Sunday, January 6, 2008
Java Example Event Programming
Posted by
Real Time Questions
at
11:59 PM
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment