Accessing Fields by Name


In the previous example, you added fields to the message with TipcMsgAppendStr and TipcMsgAppendReal8. Then you accessed the message fields sequentially with TipcMsgNextStr and TipcMsgNextReal8. Another way to add and access fields is to associate a name with each field. The receiving RTclient can access those fields by name.

Step 21

Edit the send3.c program

To modify the previous example to use named fields, replace lines 12-14 of send3.c with this call:

TipcMsgAddNamedReal8(msg, "Answer", (T_REAL8)42.0); 

Step 22

Edit the receive3.c program

Modify lines 17-19 of receive3.c to retrieve the field by name as:

TipcMsgGetNamedReal8(msg, "Answer", &var_value); 
TutOut("Field name: Answer, Value = %s\n", 
             TutRealToStr(var_value)); 

Note: Ignore the warning message about var_name being an unreferenced local variable.

Step 23

Compile and link the programs, then start them

After compiling and linking the modified receive3.c and send3.c programs, start them as you did earlier. First start the new receiving program. Then, after a few moments, start the sending program.

You should see this message output from the receiving program.

Contents of NUMERIC_DATA message: 
--------------------------------- 
Field name: Answer, Value = 42 

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