Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Create CORBA based server-client application (for windows)
- Software Requirements:
- 1. Java Development Kit (JDK) 8 or later
- 2. Eclipse or NetBeans IDE (optional)
- 3. JacORB or TAO CORBA implementation
- Step 1: Install JacORB or TAO CORBA implementation
- Download and install JacORB or TAO CORBA implementation:
- - JacORB: http://www.jacorb.org/
- - TAO: https://www.cs.wustl.edu/~schmidt/TAO.html
- Step 2: Create the IDL file
- Create a file called Hello.idl with the following content:
- idl
- module HelloApp
- {
- interface Hello
- {
- string sayHello();
- };
- };
- Step 3: Compile the IDL file
- Use the idlj compiler to generate the stubs and skeletons:
- bash
- idlj -fclient -fserver Hello.idl
- Step 4: Implement the server
- Create a file called HelloImpl.java with the following content:
- import HelloApp.*;
- import org.omg.CORBA.*;
- public class HelloImpl extends HelloPOA
- {
- public String sayHello()
- {
- return "Hello, world!";
- }
- }
- Step 5: Create the server
- Create a file called HelloServer.java with the following content:
- import HelloApp.*;
- import org.omg.CORBA.*;
- public class HelloServer
- {
- public static void main(String[] args)
- {
- try
- {
- ORB orb = ORB.init(args, null);
- HelloImpl helloImpl = new HelloImpl();
- orb.connect(helloImpl);
- String[] args2 = new String[] {"-ORBInitialPort", "1050"};
- NamingContextExt namingContext = NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
- namingContext.bind("Hello", helloImpl._this());
- System.out.println("Hello server ready...");
- orb.run();
- }
- catch (Exception e)
- {
- System.out.println("Error: " + e.getMessage());
- }
- }
- }
- Step 6: Implement the client
- Create a file called HelloClient.java with the following content:
- import HelloApp.*;
- import org.omg.CORBA.*;
- public class HelloClient
- {
- public static void main(String[] args)
- {
- try
- {
- ORB orb = ORB.init(args, null);
- String[] args2 = new String[] {"-ORBInitialPort", "1050"};
- NamingContextExt namingContext = NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
- Hello hello = HelloHelper.narrow(namingContext.resolve_str("Hello"));
- System.out.println(hello.sayHello());
- }
- catch (Exception e)
- {
- System.out.println("Error: " + e.getMessage());
- }
- }
- }
- Step 7: Compile and run the application
- Compile the server and client files:
- bash
- javac *.java
- Run the server:
- bash
- java HelloServer -ORBInitialPort 1050
- Run the client:
Advertisement
Add Comment
Please, Sign In to add comment