REMOTE METHOD INVOCATION - IIOP


AIM:
    To write a Java program for the implementation of RMI for IIOP.

ALGORITHM:

SERVER SIDE:
Step 1: Start
Step 2: Define the class helloserver
Step 3: Create the objects helloref, InitialNamingContext in try
Step 4: Register the object helloref
Step 5: Display the exception in catch
Step 6: Stop

CLIENT SIDE:
Step 1: Start
Step 2: Define the class helloclient
Step 3: Declare the objects ic, objref, hi
Step 4: Initialize the objects ic, objref in try
Step 5: Obtain a reference to server
Step 6: Call the method sayhello by passing the argument “mars”
Step 7: Display the exception in catch
Step 8: Stop

SOURCE CODE:

hellointerface.java
import java.rmi.*;
import java.rmi.Remote;

public interface hellointerface extends Remote
{
   public void sayhello(String from)throws RemoteException;
}

helloimpl.java
import java.rmi.*;
import javax.rmi.PortableRemoteObject;
public class helloimpl extends PortableRemoteObject implements hellointerface
{
   public helloimpl() throws RemoteException
   {
      super();
   }
   public void sayhello(String from)throws RemoteException
   {
      System.out.println("\nHello from "+from);
   }
}

helloclient.java
import java.rmi.RemoteException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import javax.rmi.*;
import java.util.Vector;
import javax.naming.NamingException;
import javax.naming.InitialContext;
import javax.naming.Context;
public class helloclient
{
   public static void main(String args[])throws Exception
   {
      Context ic;
      Object objref;
      hellointerface hi;
      try
      {
         ic=new InitialContext();
         objref=ic.lookup("helloservice");
         System.out.println("\nClient obtained a ref to server");
         hi=(hellointerface)PortableRemoteObject.narrow(objref,hellointerface.class);
         hi.sayhello("mars");
      }
      catch(Exception e)
      {
         System.out.println("Exception:"+e);
         return;
      }
   }
}

helloserver.java
import javax.naming.InitialContext;
import javax.naming.Context;
public class helloserver
{
   public static void main(String args[])
   {
      try
      {
         helloimpl helloref=new helloimpl();
         Context InitialNamingContext=new InitialContext();
         InitialNamingContext.rebind("helloservice",helloref);
         System.out.println("\nObject is registered");
      }
      catch(Exception e)
      {
         System.out.println("Exception:"+e);
      }
   }
}

OUTPUT:

CONNECTION:

SERVER SIDE:

CLIENT SIDE:














RESULT:
          Thus the Java program for Remote Method Invocation for IIOP was performed and the output was verified.

.
Previous
Next Post »

Still not found what you are looking for? Try again here.