RMI IMPLEMENTATION



Aim:
            To work with distributed environment using rmi concept.
Algorithm:
Step 1: Create a folder inside any drive.
Step 2: Inside the folder create 3 sub folders called server,client,registry.
Step3: Inside the server folder create 2 java programs
1.      Remote interface
2.      Java Class
Step 4: Open 3 command prompt and get inside the paths
1.      Folder_name/client
2.      Folder_name/server
3.      Folder_name/registry
Step 5: In registry command prompt, give command rmiregistry to start registry.
Step 6: Compile the files in server,
1.      Comple interface
2.      Compile class
3.      Create stub class
Step 7: From server folder copy interface class and stub class and paste inside client and registry.
Step 8: create java file inside server to rebind class in registry.
Step 9: create client program in client to lookup the class object from registry.
Step 10: compile and run those two programs.

Server
helloc_Stub.class
helloi.class
client.class
regis.class
Remote Interface:
import java.rmi.*;
public interface helloi extends Remote
{
public String display(String s) throws RemoteException;
}
Class:
import java.rmi.*;
import java.rmi.server.*;

public class helloc extends UnicastRemoteObject implements helloi
{
public helloc() throws RemoteException {}
public String display(String s) throws RemoteException
{
return "saravana "+s;
}
}
Binding in registry:
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
public class regis
{
public static void main(String args[]) throws Exception
{
helloc h=new helloc();
Naming.rebind("saravana",h);
}
}
Client
helloc_Stub.class
helloi.class
client.class
Lookup:
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
public class client
{
public static void main(String args[]) throws Exception
{
helloi h=(helloi)Naming.lookup("Saravana");
System.out.println(h.display("Hai"));
}
}
Registry
helloc_Stub.class
helloi.class

Execution
Registry:        rmiregistry
Server:                        javac helloi.java
                        Javac helloc.java
                        Rmic helloc
                        Javac regis.java
Client             javac client.java
Server             java regis
Client                         java client












Output:
D:\rmi\client>java client
Hai saravana

0 comments: