[Enterprise Extensions only]
  Next topic

Creating the CORBA client main code (client.cpp)

Use this task to create the main code for a CORBA client, to locate a servant object hosted by a CORBA server and to call methods on the server object. The client's main method performs the following tasks:

  1. Validating user input
  2. Initializing the client environment
  3. Getting a pointer to the root naming context
  4. Accessing the servant object
  5. Calling methods on the servant object
  6. Stopping the client and releasing resources used

To create the main code for a CORBA client, complete the following steps:

  1. Create a source file,client.cpp, where client is the name of the client program.
  2. Edit the client source file, client.cpp, to add appropriate code to implement the client. To do this, complete the following steps:
    1. Add include statements and global declarations needed, as described in Creating CORBA client main code (client.cpp), adding include statements and global declarations.
    2. Add the main method, in the form:
      main(int argc, char *argv[])
      {
        int rc;
        ::CORBA::Object_ptr objPtr;
        ::CosNaming::NamingContext_var rootNameContext = NULL;
        Servant_var liptr = NULL;
      
        exit( 0 );
      }
       
  3. Add code to check the input parameters provided on the command used to start the client, as described in Creating CORBA client main code (client.cpp), adding code to check input parameters.
  4. Add code to initialize the client environment, as described in Creating CORBA client main code (client.cpp), adding code to initialize the client environment.
  5. Add code to get a pointer to the root naming context, as described in Creating CORBA client main code (client.cpp), adding code to get a pointer to the root naming context.
  6. Add code to access the servant object that has already been created by the server, as described in Creating CORBA client main code (client.cpp), adding code to access the servant object.
  7. Add code to call methods on the servant object, as described in Creating CORBA client main code (client.cpp), adding code to call methods on the servant object.
  8. Add code to shutdown the client and release resources used, as described in Creating CORBA client main code (client.cpp), adding code to shutdown the client and release resources used.

This task is one step of the parent task, Developing a CORBA client.

  Next topic