In this section, you see the complete C source code for your first program.
Copy the send.c program
Copy the send.c
program into your working directory. Under Windows you must also copy the makefile sendw32m.mak
into your tutorial directory. Under Windows you can work with an editor in a Command Prompt window or use the Visual C++ Developer Studio to edit and build your tutorial programs. Use the command chmod 777 *
to allow write access to any sample programs you copy.
Line numbers appear on the far left margins of code examples. They are not part of the program but are used throughout this tutorial to refer back to different lines of source code. There is no error handling shown in the examples in this tutorial. Error handling is briefly explained later in this lesson. Here is an example of the file send.c
program:
/* send.c - send an INFO message to /lesson1 subject */
/* $RTHOME/examples/smrtsock/tutorial/lesson1/send.c */
1 #include <rtworks/ipc.h> 2 int main(int argc, char **argv) { 3 TipcSrvMsgWrite("/tutorial/lesson1", TipcMtLookupByNum(T_MT_INFO), TRUE, _IPC_FT_STR, "Hello World!", NULL); 4 TipcSrvFlush(); 5 TipcSrvDestroy(T_IPC_SRV_CONN_NONE); }/* main */
You are probably finding it hard to believe that a complete TIBCO SmartSockets program can be only a few lines of code. This is one of the main benefits of TIBCO SmartSockets; hundreds of lines of interprocess communication code, such as sockets or RPCs, can be reduced to just a few lines of TIBCO SmartSockets code.
The first thing you should notice about your sending program is that the header file, ipc.h
, is required to compile and link TIBCO SmartSockets programs. It must be part of any file that refers to the TIBCO SmartSockets API. For more information on TIBCO SmartSockets include files see the TIBCO SmartSockets Application Programming Interface reference.
There are only four calls to the TIBCO SmartSockets API in this program: TipcSrvMsgWrite, TipcMtLookupByNum, TipcSrvFlush, and TipcSrvDestroy. From the API naming conventions, you can infer that the called functions TipcSrvMsgWrite, TipcSrvFlush, and TipcSrvDestroy are all used to communicate with an RTserver, because they start with the prefix TipcSrv. TipcMtLookupByNum is used to get information about a message type, consistent with its TipcMt prefix.
This message publishing program consists of only three lines of code:
Compile and link the program
Now the program must be compiled and linked. This is accomplished using the TIBCO SmartSockets shell script rtlink
under UNIX or OpenVMS, and a TIBCO SmartSockets-supplied makefile invoked from either the command line or Developer Studio under Windows, as shown:
Set paths for the include files and libraries
Under Windows, if you are using TIBCO SmartSockets for the first time, you need to set the paths for your include files and libraries so Developer Studio will find the TIBCO SmartSockets include files and libraries. You’ll also need to set the Project settings within Developer Studio. See the TIBCO SmartSockets Installation Guide for Windows for details on this.
Build your program
Once you’ve set the include, library and project settings, to compile and link the program within Developer Studio, select File > Open Workspace..., select filename sendw32m.mak
from your tutorial directory, and then select Build > Build send.
The rtlink
shell script compiles and links a program with the TIBCO SmartSockets libraries. This example compiles the program send.c
, links it, and creates the executable send.x
(on OpenVMS and Windows: send
). Compiling and linking can be done in separate steps, and there are many options available. You can also define your own make file and choose your own compiler.
Once compiled, the program is ready to run. Before running it, you need to create a second program, receive.c
, to read and print the message that is being sent.
TIBCO SmartSockets™ Tutorial Software Release 6.8, July 2006 Copyright © TIBCO Software Inc. All rights reserved www.tibco.com |