A common way of troubleshooting a TIBCO SmartSockets project is to log the messages that are coming into or going out of a process. In TIBCO SmartSockets, messages can be logged in text or binary files. The text message files can be easily transported to a different platform. These message files can also be read and replayed using the TipcMsgFile* TIBCO SmartSockets API.
As described in the section on message files in the messages chapter of the TIBCO SmartSockets User’s Guide, a message file is a file (in either text format or binary format) containing one or more messages. Through the use of options, RTclient can easily log (write into message files) the messages sent to or received from RTserver. For message file logging, the message types are grouped into three standard categories: data, status, and internal. The message types that fall into these categories are described in the publish-subscribe chapter of the TIBCO SmartSockets User’s Guide.
An RTclient starts and stops logging messages in the logging categories by setting the options listed in this table:
RTserver can also log incoming and outgoing messages to message files. See the section on message file logging in the publish-subscribe chapter of the TIBCO SmartSockets User’s Guide for more information.
In the next lesson you learn how to add your own message types to TIBCO SmartSockets. These message types can also be logged into any of the three categories (data, status, internal) discussed earlier. A message type is assigned to a category for logging using the TipcSrvLogAddMt function. See TipcSrvLogAddMt in the TIBCO SmartSockets Application Programming Interface for more details.
Message logging is started by setting one of the above options (either with the function TutOptionSetStr or the setopt command) to the name of a file. For example:
The above example causes the RTclient to start logging all incoming data messages into the incoming.msg
file. If the file does not exist, it is created. If the file exists from a previous session, it is overwritten with new information.
You are now going to add message logging to both your sending and receiving programs.
Edit the original send3.c program
In the original send3.c
, edit the program and add this line before the call to TipcSrvCreate, which tries to connect the program to RTserver:
This line causes all data messages which leave the sending program, such as NUMERIC_DATA, to be written to the file send3.msg
.
Edit the receive3.c program
In a similar manner, in receive3.c
, before the call to TipcSrvCreate, add this line:
In previous programs you used calls to TutOption* routines to set options. Here, you use a new TIBCO SmartSockets utility function, TutCommandParseStr, which can be used to execute a TIBCO SmartSockets command, such as setopt
, which sets an option. This line causes all data messages, such as NUMERIC_DATA, which are input to the receive3
program, to be written to the file receive3.msg
.
Compile and link the programs
To see the logging occur, first compile and link receive3.c
and send3.c
.
Start the programs
Start the new receiving and sending programs in separate windows as you did earlier, starting the receiving program first:
You should still see this message output from the receiving program:
Contents of NUMERIC_DATA message: --------------------------------- Var name = X, Var Value = 10 Var name = Y, Var Value = 20 Var name = Z, Var Value = 30
Check the log file
Now, check the log file from the sending program by typing it on your display using this command:
The contents of the file should look like:
Check the other log file
Check the log file from the receiving program using this command:
The contents of the file should look like:
Message logging is stopped by setting the logging options to UNKNOWN
(either with the function TutOptionSetUnknown or the unsetopt command). For example:
or
This example causes the RTclient to stop logging all incoming data messages. If multiple categories are being logged to the same file, the file is not closed until logging is stopped for all the relevant categories.
TIBCO SmartSockets™ Tutorial Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |