Simple Calculator Client

The next thing you have to do is to write the server and client programs. We start with the client, because it's easier and not very complicated.

A simple implementation of the client might look like this

Example 1-2. Calculator Client C Source

#include <orb/orbit.h>
#include "calculator.h"

int
main(int argc, char* argv[])
{
        CORAB_Environment env;
	CORBA_ORB         orb;
	CORBA_Object      server;
        CORBA_double      res;

	CORBA_exception_init(&ev);
	orb = CORBA_ORB_init(&argc, &argv, "orbit-local-orb", &ev);
	server = CORBA_ORB_string_to_object(orb, argv[1], &ev);
        res = Calculator_add(1.0, 2.0, &ev);
	fprintf("1.0 + 2.0 = %2.0f\n", res);
	CORBA_Object_release(server);
	exit(0);
};
          
Rather simple, but full of unexplained stuff. Let's take a close look to the defined variables.

env

This varaible is used to hold information about exceptions which might have occurred during a function call. How to use this variable to detect errors in function will be explained in a later example.

orb

This is the ORB itself.

server

This is the object reference to the server.

The example above is a full functional client. The magic in this exmample is the usage of the function CORBA_ORB_string_to_object with the paramter argv[1]. The explantion is that the program is supposed to be called with the string representation of the Calculator server as the first parameter. How to obtain this string, will be shown in the next exmaple, where i describe how the server looks like.