Often, when writing an application to read and process messages, your program may at times be doing other things when messages arrive. Rather than ignore the messages, TIBCO SmartSockets provides a very flexible buffering mechanism such that the messages are stored until they are ready to be processed.
Copy the receive3.c and send3.c files
To illustrate this important concept, copy the files receive3.c
and send3.c
into your working directory. Under Windows copy the makefiles rcv3w32m.mak
and snd3w32m.mak
into your current directory.
The receive3.c
file contains a new while loop that causes the program to read and process messages for two seconds, and then sleep for ten seconds. While sleeping, any messages that arrive are buffered. The difference between the receive2.c
and receive3.c
program is this while loop in receive3.c
:
/* Read and Process all incoming messages */
while (1) {
TipcSrvMainLoop(2.0);
TutOut("Sleeping...\n");
TutSleep(10.0);
TutOut("...Done Sleeping!\n");
}
Compile, link, and start the receiving program
To see the TIBCO SmartSockets message buffering in action, first compile and link the receive3.c
program. Then start the receiving program:
Compile, link, and start the sending program
Now, in a different window, do the same for the send3.c
program. Compile and link it the send3.c
program. Then start the sending program:
The sending program is sending messages once a second. The receiving program is reading and processing messages for two seconds and then sleeping for 10 seconds. This output displays in the window where the receiving program is running:
Sleeping... ...Done Sleeping! Message Count = 1 Message Count = 2 Message Count = 3 Message Count = 4 Message Count = 5 Message Count = 6 Message Count = 7 Message Count = 8 Message Count = 9 Sleeping... ...Done Sleeping! Message Count = 10 Message Count = 11 Message Count = 12 Message Count = 13 Message Count = 14 Message Count = 15 Message Count = 16 Message Count = 17 Message Count = 18 Message Count = 19 Message Count = 20 Sleeping...
As you watch the receiving program run, notice that while sleeping, it does not read or process any messages. When it is finished sleeping, it reads and processes all the messages it has in its buffer. This is why you see the messages output in quick bursts.
Stop all RTclients
Before proceeding to the next section, stop the RTserver and its RTclients with this command:
TIBCO SmartSockets™ Tutorial Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |