DS Experiment No 8

Aim- To write a program to print “Hello World” in CORBA.
 download now

Hello.idl
module HelloApp{
 interface Hello  {
 string sayHello();
 oneway void shutdown();
 };
};

HelloServer.java
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import java.util.Properties;
class HelloImpl extends HelloPOA{
 private ORB orb;
public void setORB(ORB orb_val){
   orb = orb_val;  }
 public String sayHello(){
   return "\nHello world !!\n";  }
  public void shutdown(){
   orb.shutdown(false);  }}
public class HelloServer{
 public static void main(String args[]){
   try{
     ORB orb = ORB.init(args, null);
     POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
     rootpoa.the_POAManager().activate();
     HelloImpl helloImpl = new HelloImpl();
     helloImpl.setORB(orb);
     HelloPOATie tie = new HelloPOATie(helloImpl, rootpoa);
     Hello href = tie._this(orb);
     org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
     NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
     String name = "Hello";
     NameComponent path[] = ncRef.to_name( name );
     ncRef.rebind(path, href);
     System.out.println("HelloServer ready and waiting ...");
     orb.run(); }
    catch (Exception e){
     System.err.println("ERROR: " + e);
     e.printStackTrace(System.out);}
   System.out.println("HelloServer Exiting ..."); }}



HelloClient.java
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
public class HelloClient{
public static void main(String args[]){
     try{
     ORB orb = ORB.init(args, null);
     org.omg.CORBA.Object objRef =
         orb.resolve_initial_references("NameService");
     NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
     String name = "Hello";
     Hello helloImpl = HelloHelper.narrow(ncRef.resolve_str(name));
     System.out.println("Obtained a handle on server object: " + helloImpl);
     System.out.println(helloImpl.sayHello());
     helloImpl.shutdown();
     }
      catch (Exception e) {
     System.out.println("ERROR : " + e)
e.printStackTrace(System.out);
   }
 }
}
OUTPUT:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Windows\system32>cd\

C:\>cd C:\jdk1.8.0_111\bin
C:\jdk1.8.0_111\bin>java HelloClient -ORBInitialPort 1050 -ORBInitialHost localh
ost
Obtained a handle on server object: IOR:000000000000001749444c3a48656c6c6f417070
2f48656c6c6f3a312e300000000000010000000000000086000102000000000b31302e312e37352e
35330000c0e1000000000031afabcb0000000020a778de0900000001000000000000000100000008
526f6f74504f41000000000800000001000000001400000000000002000000010000002000000000
0001000100000002050100010001002000010109000000010001010000000026000000020002

Hello world !!



DS Experiment No 8 DS Experiment No 8 Reviewed by akshay salve on 10:33 PM Rating: 5

No comments:

Powered by Blogger.