The next program, receive.c
, reads and prints out the contents of the message being published from the send.c
program described in the previous section.
Copy the receive.c program
Copy the program receive.c
into your tutorial directory. Under Windows also copy the associated makefile, recvw32m.mak
, into your tutorial directory. Here is an example of the receive.c
program:
/* receive.c - read and print an INFO message */
/* $RTHOME/examples/smrtsock/tutorial/lesson1/receive.c */
1 #include <rtworks/ipc.h> 2 int main(int argc, char **argv) { 3 T_IPC_MSG msg; 4 T_STR msg_text; 5 TipcSrvSubjectSetSubscribe("/tutorial/lesson1", TRUE); 6 msg = TipcSrvMsgNext(T_TIMEOUT_FOREVER); 7 TipcMsgSetCurrent(msg, 0); 8 TipcMsgNextStr(msg, &msg_text); 9 TutOut("Text from message = %s\n", msg_text); 10 TipcSrvDestroy(T_IPC_SRV_CONN_NONE); }/* main */
As with the send.c
program, notice how the program consists of so few lines of code. Compare this with a similar program written using pipes, sockets or shared memory. Not only are TIBCO SmartSockets programs much shorter, they also have many built-in features (such as automatic data conversion across heterogeneous platforms). Let’s examine this program on a line-by-line basis to understand in detail how the program works:
Compile and link the program
Now you must compile and link the receiving program in a similar manner as before:
Build the receiving program
Under Windows, to compile and link the receiving program within Developer Studio, select File > Open Workspace..., select filename recvw32m.mak
from your tutorial directory, and then select Build > Build receive.
All further examples in this Tutorial will assume that you are familiar with compiling and linking programs as described above.
TIBCO SmartSockets™ Tutorial Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |