Tuxedo简单实例

来源:互联网 发布:spss v24 激活码mac 编辑:程序博客网 时间:2024/05/01 14:29

我们就拿Tuxedo提供的例子做下修改吧,首先说明运行系统是windows环境下。

1.设置环境变量

setenv.cmd

rem(c) 2003 BEA Systems, Inc. All Rights Reserved.rem     Copyright (c) 2000 BEA Systems, Inc.rem       All Rights Reservedrem     THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OFrem     BEA Systems, Inc.rem     The copyright notice above does not evidence anyrem     actual or intended publication of such source code.rem     Copyright (c) 2000 BEA Systems, Inc.rem     All rights reservedrem     ident"@(#) apps/simpapp/setenv.cmd$Revision: 1.5 $"      set TUXDIR=C:\bea\tuxedo8.1set APPDIR=C:\bea\tuxedo8.1\samples\atmi\simpappset PATH=%TUXDIR%\bin;%APPDIR%;%PATH%set TUXCONFIG=F:\Liwei\Tuxedo\dbread\tuxconfig1


2.修改ubbsimple,需要改动的我标记了,ubbsimple配置文件最为重要,一定要修改对了


#    (c) 2003 BEA Systems, Inc. All Rights Reserved.#ident    "@(#) samples/atmi/simpapp/ubbsimple    $Revision: 1.5 $"#Skeleton UBBCONFIG file for the TUXEDO Simple Application.#Replace the <bracketed> items with the appropriate values.*RESOURCESIPCKEY        223357             ##########此处需要改动,范围:32769到262126#Example:#IPCKEY        123456DOMAINID    simpappMASTER        simpleMAXACCESSERS    10MAXSERVERS    5MAXSERVICES    10MODEL        SHMLDBAL        N*MACHINESDEFAULT:        APPDIR="C:\bea\tuxedo8.1\samples\atmi\simpapp"            ######需改动,应用程序目录        TUXCONFIG="F:\Liwei\Tuxedo\dbread\tuxconfig1"             ######需改动,生成配置文件目录        TUXDIR="C:\bea\tuxedo8.1"                                 ######需改动,TUXEDO安装目录#Example:#        APPDIR="/home/me/simpapp"#        TUXCONFIG="/home/me/simpapp/tuxconfig"#        TUXDIR="/usr/tuxedo"UUG87MMYP9NXUFL    LMID=simple                                     ######需改动,UUG87MMYP9NXUFL为你计算机名#Example:#beatux        LMID=simple*GROUPSGROUP1    LMID=simple    GRPNO=1    OPENINFO=NONE*SERVERSDEFAULT:        CLOPT="-A"simpserv    SRVGRP=GROUP1 SRVID=1*SERVICESTOUPPER

3.客户端代码,simpcl.c

/*(c) 2003 BEA Systems, Inc. All Rights Reserved. *//*Copyright (c) 1997 BEA Systems, Inc.  All rights reserved  THIS IS UNPUBLISHED PROPRIETARY  SOURCE CODE OF BEA Systems, Inc.  The copyright notice above does not  evidence any actual or intended  publication of such source code.*//* #ident"@(#) samples/atmi/simpapp/simpcl.c$Revision: 1.5 $" */#include <stdio.h>#include "atmi.h"/* TUXEDO  Header File */#if defined(__STDC__) || defined(__cplusplus)main(int argc, char *argv[])#elsemain(argc, argv)int argc;char *argv[];#endif{char *sendbuf, *rcvbuf;long sendlen, rcvlen;int ret;if(argc != 2) {(void) fprintf(stderr, "Usage: simpcl string\n");exit(1);}/* Attach to System/T as a Client Process */if (tpinit((TPINIT *) NULL) == -1) {(void) fprintf(stderr, "Tpinit failed\n");exit(1);}sendlen = strlen(argv[1]);/* Allocate STRING buffers for the request and the reply */if((sendbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) {(void) fprintf(stderr,"Error allocating send buffer\n");tpterm();exit(1);}if((rcvbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) {(void) fprintf(stderr,"Error allocating receive buffer\n");tpfree(sendbuf);tpterm();exit(1);}(void) strcpy(sendbuf, argv[1]);/* Request the service TOUPPER, waiting for a reply */ret = tpcall("TOUPPER", (char *)sendbuf, 0, (char **)&rcvbuf, &rcvlen, (long)0);if(ret == -1) {(void) fprintf(stderr, "Can't send request to service TOUPPER\n");(void) fprintf(stderr, "Tperrno = %d\n", tperrno);tpfree(sendbuf);tpfree(rcvbuf);tpterm();exit(1);}(void) fprintf(stdout, "Returned string is: %s\n", rcvbuf);/* Free Buffers & Detach from System/T */tpfree(sendbuf);tpfree(rcvbuf);tpterm();return(0);}

4.服务器端代码:simpserv.c

/*(c) 2003 BEA Systems, Inc. All Rights Reserved. *//*Copyright (c) 1997 BEA Systems, Inc.  All rights reserved  THIS IS UNPUBLISHED PROPRIETARY  SOURCE CODE OF BEA Systems, Inc.  The copyright notice above does not  evidence any actual or intended  publication of such source code.*//* #ident"@(#) samples/atmi/simpapp/simpserv.c$Revision: 1.5 $" */#include <stdio.h>#include <ctype.h>#include <atmi.h>/* TUXEDO Header File */#include <userlog.h>/* TUXEDO Header File *//* tpsvrinit is executed when a server is booted, before it begins   processing requests.  It is not necessary to have this function.   Also available is tpsvrdone (not used in this example), which is   called at server shutdown time.*/#if defined(__STDC__) || defined(__cplusplus)tpsvrinit(int argc, char *argv[])#elsetpsvrinit(argc, argv)int argc;char **argv;#endif{/* Some compilers warn if argc and argv aren't used. */argc = argc;argv = argv;/* userlog writes to the central TUXEDO message log */userlog("Welcome to the simple server");return(0);}/* This function performs the actual service requested by the client.   Its argument is a structure containing among other things a pointer   to the data buffer, and the length of the data buffer.*/#ifdef __cplusplusextern "C"#endifvoid#if defined(__STDC__) || defined(__cplusplus)TOUPPER(TPSVCINFO *rqst)#elseTOUPPER(rqst)TPSVCINFO *rqst;#endif{int i;for(i = 0; i < rqst->len-1; i++)rqst->data[i] = toupper(rqst->data[i]);/* Return the transformed buffer to the requestor. */tpreturn(TPSUCCESS, 0, rqst->data, 0L, 0);}



4.ok,到这基本配置已经写好了,我们就开始编译测试。首先执行setenv.cmd设置环境变量。(注意:如果你之前做过设置,这次有所改动,在我的电脑-高级-环境变量下面你所看到的和文件里面的是不一样的,如果不一样,就需要手动设置。运行cmd命令-输入env你会看到你所有的系统环境变量,和setenv.cmd文件对比,如果一样,ok,不管了,如果不一样,在cmd下设置:如set TUXCONFIG=F:\Liwei\Tuxedo\dbread\tuxconfig1)


5.生成二进制配置文件;cmd下进入你的应用程序目录 ,输入:tmloadcf -y ubbsimple,如果不报错,会在F:\Liwei\Tuxedo\dbread\下生成tuxconfig1,否则检查错误原因

6.编译客户端程序 ,cmd下输入:buildclient -o simpcl.exe -f simpcl.c  ,结果如下图:



7.编译服务器端,cmd下输入:buildserver -o simpserv.exe -f simpserv.c -s TOUPPER


8.启动服务程序,cmd下输入:tmboot -y

9.运行客户端程序,cmd下输入:simpcl "hello world!"


ok,测试成功,关闭应用程序用:tmshutdown -y



原创粉丝点击