Hello.
idl module HelloApp { interface Hello { string sayHello(); oneway void shutdown(); }; };
[Link]
import import import import
HelloApp.*; [Link].*; [Link].*; [Link].*;
public class HelloClient { static Hello helloImpl; public static void main(String args[]) { try{ // create and initialize the ORB ORB orb = [Link](args, null); // get the root naming context [Link] objRef = orb.resolve_initial_references("NameService"); // Use NamingContextExt instead of NamingContext. This is // part of the Interoperable naming Service. NamingContextExt ncRef = [Link](objRef); // resolve the Object Reference in Naming String name = "Hello"; helloImpl = [Link](ncRef.resolve_str(name)); [Link]("Obtained a handle on server object: " + helloImpl); [Link]([Link]()); [Link](); } catch (Exception e) { [Link]("ERROR : " + e) ; [Link]([Link]); } } }
[Link] import HelloApp.*;
import import import import import
[Link].*; [Link].*; [Link].*; [Link].*; [Link];
import [Link]; class HelloImpl extends HelloPOA { private ORB orb; public void setORB(ORB orb_val) { orb = orb_val; } // implement sayHello() method public String sayHello() { return "\nHello world !!\n"; } // implement shutdown() method public void shutdown() { [Link](false); } } public class HelloServer { public static void main(String args[]) { try{ // create and initialize the ORB ORB orb = [Link](args, null); // get reference to rootpoa & activate the POAManager POA rootpoa = [Link](orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate(); // create servant and register it with the ORB HelloImpl helloImpl = new HelloImpl(); [Link](orb); // get object reference from the servant [Link] ref = rootpoa.servant_to_reference(helloImpl); Hello href = [Link](ref); // get the root naming context // NameService invokes the name service [Link] objRef = orb.resolve_initial_references("NameService"); // Use NamingContextExt which is part of the Interoperable // Naming Service (INS) specification. NamingContextExt ncRef = [Link](objRef); // bind the Object Reference in Naming String name = "Hello"; NameComponent path[] = ncRef.to_name( name ); [Link](path, href);
[Link]("HelloServer ready and waiting ..."); // wait for invocations from clients [Link](); } catch (Exception e) { [Link]("ERROR: " + e); [Link]([Link]); } [Link]("HelloServer Exiting ..."); } }
Output:-
Terminal1:
Last login: Tue Mar 6 [Link] on ttys000 Digvijay-Singhs-MacBook-Pro:~ Digvijay$ cd Desktop/ Digvijay-Singhs-MacBook-Pro:Desktop Digvijay$ cd Corba/
Digvijay-Singhs-MacBook-Pro:Corba Digvijay$ idlj -fall [Link] Digvijay-Singhs-MacBook-Pro:Corba Digvijay$ javac *.java HelloApp/*.java Note: HelloApp/[Link] uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Digvijay-Singhs-MacBook-Pro:Corba Digvijay$ orbd -ORBInitialPort 1050& [1] 336 Digvijay-Singhs-MacBook-Pro:Corba Digvijay$ java HelloServer -ORBInitialPort 1050 -ORBInitialHost localhost& [2] 339 Digvijay-Singhs-MacBook-Pro:Corba Digvijay$ HelloServer ready and waiting ... HelloServer Exiting ... Mar 6, 2012 [Link] AM [Link] checkShutdownState WARNING: "IOP01600004: (BAD_INV_ORDER) ORB has shutdown" Digvijay-Singhs-MacBook-Pro:Corba Digvijay$
Terminal 2:
Last login: Tue Mar 6 [Link] on ttys000 Digvijay-Singhs-MacBook-Pro:~ Digvijay$ cd Desktop/ Digvijay-Singhs-MacBook-Pro:Desktop Digvijay$ cd Corba/ Digvijay-Singhs-MacBook-Pro:Corba Digvijay$ java HelloClient -ORBInitialPort 1050 -ORBInitialHost localhost Obtained a handle on server object: IOR:000000000000001749444c3a48656c6c6f4170702f48656c6c6f3a312e3000000 00000010000000000000082000102000000000a3132372e302e302e3100c0120000 0031afabcb0000000020e5e23f1a00000001000000000000000100000008526f6f745 04f41000000000800000001000000001400000000000002000000010000002000000 0000001000100000002050100010001002000010109000000010001010000000026 000000020002 Hello world !! Digvijay-Singhs-MacBook-Pro:Corba Digvijay$