Corba
Corba
The Common Object Request Broker Architecture (CORBA) is a standard developed by the Object
Management Group (OMG) to provide interoperability among distributed objects. CORBA is the
world’s leading middleware solution enabling the exchange of information, independent of
hardware platforms, programming languages, and operating systems. CORBA is essentially a
design specification for an Object Request Broker (ORB), where an ORB provides the mechanism
required for distributed objects to communicate with one another, whether locally or on remote
devices, written in different languages, or at different locations on a network.
In this CORBA Programming tutorial, we will learn how to create :
• Simple Remote Object.
• Server to instantiate (create ) and bind a remote object.
• Client to invoke remotely an object
You need to install the Java Development Kit ( JDK ) as well as a programming editor ( IDE ) such
as Eclipse. For more details of how to install JDK and Eclipse, Use the following tutorial:
Java Programming : Creating a simple java project using Eclipse
The structure of the files for the projects created using Eclipse throughout this tutorials is shown
below:
1. Server Side
1 Let’s create a new Java Project using Eclipse ( or NetBeans or other editor you prefer), and call it
: CorbaAdditionServer-> Click Finish once done
2 Under the project CorbaAdditionServer, Create a new file called Addition.idl. Copy the code
below into the new file.
/** * * @author imed */module AdditionApp{ interface Addition { long add(in
long a,in long b); oneway void shutdown(); };};
3 Open your CMD console, Change directory ( cd ) to src folder within the project location. The
location of your project can be known through clicking: Select the project CorbaAdditionServer,
click : File -> Properties
cd C:\Users\imed\workspace\CorbaAdditionServer\src
4 Compile the idl file using the idlj command as below:
idlj -fall Addition.idl
You will see that inside the src folder, new directory called AdditionApp is created with a number
of Java files inside.
7 Under the project CorbaAdditionServer, Create a new Class called StartServer. Copy the code
below into the new class.
/** * * @author imed */import AdditionApp.*; 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; public class StartServer { public static void
main(String args[]) { try{ // create and initialize the ORB //// get
reference to rootpoa & activate the POAManager ORB orb = ORB.init(args,
null); POA rootpoa =
POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate(); // create servant and register it
with the ORB AdditionObj addobj = new AdditionObj();
addobj.setORB(orb); // get object reference from the servant
org.omg.CORBA.Object ref = rootpoa.servant_to_reference(addobj); Addition
href = AdditionHelper.narrow(ref); org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService"); NamingContextExt ncRef =
NamingContextExtHelper.narrow(objRef); NameComponent path[] =
ncRef.to_name( "ABC" ); ncRef.rebind(path, href);
System.out.println("Addition Server ready and waiting ..."); // wait for
invocations from clients for (;;){ orb.run(); } } catch
(Exception e) { System.err.println("ERROR: " + e);
e.printStackTrace(System.out); } System.out.println("HelloServer
Exiting ..."); }}
8 Open a new windows of CMD console, type in the following command to start the ORB
start orbd -ORBInitialPort 1050
9 Under Eclipse now, click on the project CorbaAdditionServer, then Click Run -> Run
Configuration as shown below:
11 Click on Arguments and type in the following arguments inside the Program arguments. Click
Apply once done:
-ORBInitialPort 1050 -ORBInitialHost localhost
12 That’s all for the server, it should be running.
Client Side.
1 Let’s create a new Java Project using Eclipse and call it : CorbaAdditionClient-> Click Finish
once done
2 Right click on AdditionApp Package under CorbaAdditionServer and click Copy
5 Click on Run -> Run Configuration, Make sure you select the StartClient for the
CorbaAdditionClient.
6 Click on Arguments, then under the Program arguments, type in the following :
-ORBInitialPort 1050 -ORBInitialHost localhost
7 Click Apply, then Run. That’s all for the client, it should be running.
Object 2
About Author
by Imed Bouchrika
Latest Comments
1. Nov 25 2013
Shreyas H J
Hello, Thanks for the above program which helped me a lot in executing and understanding
how CORBA works. Thanks again
Reply
2. Nov 25 2013
Karthik S H
Thanks. It was of great use. Nice work.
Reply
3. Nov 26 2013
Imed Bouchrika
Note that the IDL compiling should be done on client, the same way as done on the server
side.
Reply
• Nov 27 2013
SHreyas H J
• Mar 30 2015
steve
“idjl ” command not recognized at CMD .Can you please help solve the issue?
Reply
•
4. Apr 21 2014
derrick
i liked it but am using netbeans and i got lost on step 11 for the server where it required to
add arguments?????? i failed to understand it exactly tho my programm is running.
Reply
5. Jun 03 2014
Sagar
thnku for this article
Reply
6. Jun 03 2014
Sagar mal shankhala
thank you for this article
Reply
7. Jun 06 2014
Widura Wijenayake
Thanks lot, this was really helpful
Reply
8. Jul 11 2014
gihan tharnga
hehe nice works thankz lot its very clear tutoraial thank again
Reply
9. Jul 29 2014
Rajesh
Can any one Explain me the code
Reply
• May 04 2015
Nata
Hi, you maybe forgot to run the following command :
start orbd -ORBInitialPort 1050
before to run the server corba
Reply
• Dec 12 2015
mohammed
change localhost by 127.0.0.1
-ORBInitialPort 1050 -ORBInitialHost 127.0.0.1
i have the same problem but when i change to 127.0.0.1 it work’s fine
Reply
• Nov 17 2016
Wassilm
a wldi kifch sala7t waldih adhaya !!!
Reply
•