Tuxedo简单实例

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

1.设置环境变量

setenv.cmd

rem	(c) 2003 BEA Systems, Inc. All Rights Reserved.
rem     Copyright (c) 2000 BEA Systems, Inc.
rem       All Rights Reserved

rem     THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF
rem     BEA Systems, Inc.
rem     The copyright notice above does not evidence any
rem     actual or intended publication of such source code.

rem     Copyright (c) 2000 BEA Systems, Inc.
rem     All rights reserved
rem     ident	"@(#) apps/simpapp/setenv.cmd	$Revision: 1.5 $"      

set TUXDIR=C:\bea\tuxedo8.1
set APPDIR=C:\bea\tuxedo8.1\samples\atmi\simpapp
set 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.

*RESOURCES
IPCKEY        223357             ##########此处需要改动,范围:32769到262126

#Example:
#IPCKEY        123456

DOMAINID    simpapp
MASTER        simple
MAXACCESSERS    10
MAXSERVERS    5
MAXSERVICES    10
MODEL        SHM
LDBAL        N

*MACHINES
DEFAULT:
        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

*GROUPS
GROUP1
    LMID=simple    GRPNO=1    OPENINFO=NONE

*SERVERS
DEFAULT:
        CLOPT="-A"

simpserv    SRVGRP=GROUP1 SRVID=1


*SERVICES
TOUPPER

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[])
#else
main(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[])
#else
tpsvrinit(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 __cplusplus
extern "C"
#endif
void
#if defined(__STDC__) || defined(__cplusplus)
TOUPPER(TPSVCINFO *rqst)
#else
TOUPPER(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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值