46.3. Connecting to the event builder.

The code below shows how to connect to the event builder as a client:

Example 46-1. Connecting to the event builder as a data source.


    #include <CEventOrderClient>                     (1)
    ...
    std::string eventBuilderHost;                          (2)
    ...
    unsigned int evbPort;                                  (3)
    try {
        evbPort = CEventOrderClient::Lookup(eventBuilderHost);
    }
    catch (CErrnoException& e) {                      (4)
    ...
    }
    
    CEventOrderClient evb(eventBuilderHost, evbPort);    (5)
    try {
        evb.Connect();                                   (6)
    }
    catch (CErrnoException& e) {                     (7)
    ...
    }
                
(1)
As previously described, this #include is required to define the client class.
(2)
To connect to the event builder you will need to know the host on which it was started. For the sake of this example, assume thie variable will be filled in later on with the correct hostname.
(3)
This segment of code looks up the TCP/IP port on which the event builder is listening for connections. The event builder obtains a service port via the NSCLDAQ Port manager. The port manager, in turn, advertises the event buuilder service.
(4)
If the port cannot be looked up an exception is thrown. Normally you would fill in some error reporting code here.
(5)
The connection to the event builder will be encapsulated in a CEventOrderClient therefore one of these is created. Note that this does not connect to the event builder.
(6)
The Connect method actually attempts to perform the connection to the event builder.
(7)
As with Lookup an exception is thrown if the connection could not be established.