Using the C++ Class Library


The TIBCO SmartSockets C++ class library organizes the C language API into an object-oriented C++ class library. If you are already working in C++ and with object-oriented software, in general, you reap the greatest benefits in using the TIBCO SmartSockets C++ class library.

Whether to use the TIBCO SmartSockets C++ class library or the C API is up to you. The benefits of the TIBCO SmartSockets C++ class library are those that software developers have experienced when transitioning software design from purely procedural languages such as C to more object-oriented ones such as C++.

Some of the key advantages of the TIBCO SmartSockets C++ class library are:

To illustrate some of the similarities and advantages of using the C++ class library, let’s look at our earlier sending and receiving programs written in C++.

// send.cxx - send an INFO message to lesson1 subject  
// $RTHOME/examples/smrtsock/tutorial/lesson1/send.cxx  
 
#include <rtworks/sscpp.h> using namespace SmartSockets; 
 
int main(int argc, char **argv) 
{ 
  try { 
    TipcSrv srv("", NULL, NULL, NULL); 
    srv.open();   
   
    TipcMt mt(T_MT_INFO); 
 
    srv.write("/tutorial/lesson1", mt, TRUE, T_IPC_FT_STR,  
              "Hello World!", NULL); 
    srv.flush(); 
    srv.close(); 
  } 
  catch (TipcMtException mte) { 
    Utilities::out("Error in TipcMt: %s\n", mte.what()); 
  } 
  catch (TipcSrvException srve) { 
    Utilities::out("Error in TipcMsg: %s\n", srve.what()); 
  } 
 
  return 0; 
} // main 

Here is the C++ version of the receiving program:

// receive.cxx - read and print an INFO message  
// $RTHOME/examples/smrtsock/tutorial/lesson1/receive.cxx 
 
#include <rtworks/sscpp.h> using namespace SmartSockets; 
 
int main(int argc, char **argv) 
{ 
  try { 
    TipcSrv srv("", NULL, NULL, NULL); 
    srv.open();   
    char *msg_text; 
 
    TipcMsg msg(T_MT_INFO); 
    msg.setNumFields(0); 
   
    srv.setSubscribe((const char*)"tutorial/lesson1"); 
    srv.nextEx(msg, T_TIMEOUT_FOREVER); 
    msg.setCurrent(0); 
 
    msg >> msg_text; 
    Utilities::out("Text from INFO message = %s\n", msg_text); 
    srv.close(); 
  } 
  catch (TipcMsgException msge) { 
    Utilities::out("Error in TipcMsg: %s\n", msge.what()); 
  } 
  catch (TipcSrvException srve) { 
    Utilities::out("Error in TipcMsg: %s\n", srve.what()); 
  } 
 
  return 0; 
} // main  

C++ programs always have the file extension .cxx. Although this tutorial shows all the examples in C, there is also a C++ version of every program in the TIBCO SmartSockets installation directories. The C++ version has the same name as the C version except it has a .cxx extension instead of .c extension. For Windows, the C++ programs are in the directory %RTHOME%\examples\sscpp.

For more details on the C++ class library, see the TIBCO SmartSockets C++ User’s Guide.


TIBCO SmartSockets™ Tutorial
Software Release 6.8, July 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com