Coding client and server with the Interoperable Object Reference - IOR 
 

Downloads:

You will need OrbixWeb to test the client

Getting Started:

Win95 system environment settings for OrbixWeb:
 


REM
SET PATH=C:\Iona\OrbixWeb3.0\bin;%path%
REM
 

Server.java
 

// Building Distributed Object Applications with CORBA
// Infowave (Thailand) Co., Ltd.
// http://www.waveman.com
// Jan 1998

import java.io.*;

public class Server {
   public static void main(String[] args) {
      org.omg.CORBA.ORB orb = null;
      try {
         orb = org.omg.CORBA.ORB.init(args, null);
      }
      catch (org.omg.CORBA.SystemException se) { 
         System.err.println("ORB init failure " + se); 
         System.exit(1); 
      }

      org.omg.CORBA.BOA boa = null;
      try {
         boa = orb.BOA_init();
      }
      catch (org.omg.CORBA.SystemException se) { 
         System.err.println("BOA init failure " + se); 
         System.exit(1); 
      }

      // TIE uses these two new lines

      AircraftCarrierImpl new_carrier = new AircraftCarrierImpl(boa);
      Ship.AircraftCarrier carrier = new Ship._tie_AircraftCarrier(new_carrier, "Nimitz");

      try {
         boa.obj_is_ready(carrier);
      }
      catch (org.omg.CORBA.SystemException se) { 
         System.err.println("Object Ready failure " + se); 
         System.exit(1); 
      }

      System.out.println(carrier + " ready for launch !!!");

//    Write the Aircraft Carrier's object reference to an IOR file so Orbix Client can access

      try 
      {
         FileWriter output = new FileWriter("ns.ior");
         output.write(orb.object_to_string(carrier));
         output.close();
         System.out.println("Wrote AircraftCarrier's IOR to file: ns.ior");
      }
      catch(java.io.IOException e) 
      {
         System.out.println("Exception: " + e);
         System.exit(1);
      }

//    End IOR 

      try {
         boa.impl_is_ready();
      }
      catch (org.omg.CORBA.SystemException se) { 
         System.err.println("Impl Ready failure " + se); 
         System.exit(1); 
      }
   }
}
 


Client.java
 

// Building Distributed Object Applications with CORBA
// Infowave (Thailand) Co., Ltd.
// http://www.waveman.com
// Jan 1998

import java.io.*;

public class Client
{
   public static void main(String[] args)
   {
      org.omg.CORBA.ORB orb = null;
      try {
          orb = org.omg.CORBA.ORB.init(args, null);
      }
      catch (org.omg.CORBA.SystemException se) 
      { 
         System.err.println("ORB init failure " + se); 
         System.exit(1); 
      }

      org.omg.CORBA.Object objRef = null;

// Read IOR from file

      try 
      {
         LineNumberReader input = new LineNumberReader(new FileReader("ns.ior"));
         objRef = orb.string_to_object(input.readLine());
      }
      catch(java.io.IOException e) 
      {
         System.out.println("Exception: " + e);
         System.exit(1);
      }

// End IOR

      Ship.AircraftCarrier carrier = null;
      try {
         carrier = Ship.AircraftCarrierHelper.narrow(objRef);
      }
      catch (org.omg.CORBA.SystemException se) 
      { 
         System.err.println("AircraftCarrier narrow failure " + se); 
         System.exit(1); 
      }

      // Standard program continues 

      String flight = args.length > 0 ? args[0]: "Ghost Rider 101";

      Ship.Aircraft aircraft = null;
      try {
         aircraft = carrier.launch(flight);
      }
      catch (org.omg.CORBA.SystemException se) 
      { 
         System.err.println("Carrier launch failure " + se); 
         System.exit(1); 
      }

      String designation = aircraft.codeNumber();

      System.out.println ("Aircraft " + designation + " is coming your way");
   }
}
 


Building the server with VisiBroker:

Create a directory and place Ship.idl, Server.java, AircraftCarrierImpl.java, and AircraftImpl.java into it.
 


prompt> idl2java Ship.idl
prompt> vbjc Server.java
 

Building the client with OrbixWeb:

Place Client.java into the same directory as above
 


prompt> idl Ship.idl
prompt> owjavac Client.java java_output\Ship\*.java
 

Running the program:

Now start the Smart Agent and server in one window, client in another window
 


prompt> osagent
prompt> vbj Server
 
prompt> owjava Client