BEA Logo BEA Tuxedo Release 8.0

  BEA Home  |  Events  |  Solutions  |  Partners  |  Products  |  Services  |  Download  |  Developer Center  |  WebSUPPORT

 

   Tuxedo Documentation   |   Tutorials for Developing BEA Tuxedo ATMI Applications   |   Local Topics   |   Previous Topic   |   Next Topic   |   Contents

 


Step 2: Examining and Compiling the Client

How to Examine the Client

Review the ATMI client program source code:

    $ more simpcl.c

The output is shown in the following listing.

Source Code of simpcl.c

1     #include <stdio.h>         
2 #include "atmi.h" /* TUXEDO */
3
4
5
6
7 #ifdef __STDC__
8 main(int argc, char *argv[])
9
10 #else
11
12 main(argc, argv)
13 int argc;
14 char *argv[];
15 #endif
16
17 {
18
19 char *sendbuf, *rcvbuf;
20 int sendlen, rcvlen;
21 int ret;
22
23 if(argc != 2) {
24 fprintf(stderr, "Usage: simpcl string\n");
25 exit(1);
26 }
27 /* Attach to BEA TUXEDO as a Client Process */
28 if (tpinit((TPINIT *) NULL) == -1) {
29 fprintf(stderr, "Tpinit failed\n");
30 exit(1);
31 }
32 sendlen = strlen(argv[1]);
33 if((sendbuf = (char *)tpalloc("STRING", NULL, sendlen+1))== NULL){
34 fprintf(stderr,"Error allocating send buffer\n");
35 tpterm();
36 exit(1);
37 }
38 if((rcvbuf = (char *)tpalloc("STRING", NULL, sendlen+1))== NULL){
39 fprintf(stderr,"Error allocating receive buffer\n");
40 tpfree(sendbuf);
41 tpterm();
42 exit(1);
43 }
44 strcpy(sendbuf, argv[1]);
45 ret = tpcall("TOUPPER", sendbuf, NULL, &rcvbuf, &rcvlen, 0);
46 if(ret == -1) {
47 fprintf(stderr, "Can't send request to service TOUPPER\n");
48 fprintf(stderr, "Tperrno = %d, %s\n", tperrno,
49 tmemsgs[tperrno]);
50 tpfree(sendbuf);
51 tpfree(rcvbuf);
52 tpterm();
53 exit(1);
54 }
55 printf("Returned string is: %s\n", rcvbuf);
56
57 /* Free Buffers & Detach from BEA TUXEDO */
58 tpfree(sendbuf);
59 tpfree(rcvbuf);
60 tpterm();
61 }

Significant Lines in the simpcl.c Source Code

Line(s)

File/Function

Purpose




2

atmi.h

Header file required whenever BEA Tuxedo ATMI functions are used.

28

tpinit()

The ATMI function used by a client program to join an application.

33

tpalloc()

The ATMI function used to allocate a typed buffer. STRING is one of the five basic BEA Tuxedo buffer types; NULL indicates there is no subtype argument. The remaining argument, sendlen + 1, specifies the length of the buffer plus 1 for the null character that ends the string.

38

tpalloc()

Allocates another buffer for the return message.

45

tpcall()

Sends the message buffer to the TOUPPER service specified in the first argument. Also includes the address of the return buffer. tpcall() waits for a return message.

35, 41, 52, 60

tpterm()

The ATMI function used to exit an application. A call to tpterm() is used to exit the application before exiting in response to an error condition (lines 36, 42, and 53). The final call to tpterm() (line 60) is issued after the message has been printed.

40, 50, 51, 58, 59

tpfree()

Frees allocated buffers. tpfree() is the functional opposite of tpalloc().

55

printf()

The successful conclusion of the program. It prints out the message returned from the server.


 

How to Compile the Client

  1. Run buildclient to compile the ATMI client program:
        buildclient -o simpcl -f simpcl.c

    The output file is simpcl and the input source file is simpcl.c.

  2. Check the results:
    $ ls -l
    total 97
    -rwxr-x--x 1 usrid grpid 313091 May 28 15:41 simpcl
    -rw-r----- 1 usrid grpid 1064 May 28 07:51 simpcl.c
    -rw-r----- 1 usrid grpid 275 May 28 08:57 simpserv.c
    -rw-r----- 1 usrid grpid 392 May 28 07:51 ubbsimple

    As can be seen, we now have an executable module called simpcl. The size of simpcl may vary.

See Also

 

back to top previous page next page