Wednesday, December 19, 2007

JAVA 2.0 NOTE

>>PREVIOUS>>



13. Remote Method Invocation (RMI)

RMI allows java object that executes on one machine to invoke a method that executes on another machine. This is the one method of creating distributed application.

Steps to create client/server application using RMI

Write source code for interface, server and client program and compile them.

Generate Stubs and Skeletons classes by compiling server program using RMI compiler
Install files on client and server machines.

start rmiregistry on server machine to map server name to object reference

Execute the server program by java server.

Execute the client program on client machine by java client localhost args

inter.java

import java.rmi.*;

public interface inter extends Remote

{

public void getdata(int m,int n) throws RemoteException;

int adddata() throws RemoteException;

}

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("error " + e);

}

}

}

server.java

vbnm,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("Exception e");

}

}

}



14. Java Beans




>>>NEXT>>>

No comments: