TUXEDO的配置文件:
MODEL SHM
LDBAL N
*MACHINES
DEFAULT:
#服务码位置
APPDIR="/home/tuxedo/oracle/tuxedo11gR1/samples/atmi/simpapp"
#二进制码文件名
TUXCONFIG="/home/tuxedo/oracle/tuxedo11gR1/samples/atmi/simpapp/tuxconfig"
#系统位置
TUXDIR="/home/tuxedo/oracle/tuxedo11gR1"
# LMID=simple
iZ28ue01m3lZ LMID=simple
#Example:
#beatux LMID=simple
#GROUPS 节包含一些管理用信息,如设定服务或者交易的分布事务处理
*GROUPS
GROUP1
LMID=simple GRPNO=1 OPENINFO=NONE
#SERVERS节 包含需要启动的交易和其组信息等其他信息,aslan代表的是服务的可执行文件名称
*SERVERS
DEFAULT:
CLOPT="-A"
qiangdizhu SRVGRP=GROUP1 SRVID=1
# SERVICES 节包含影响应用操作方式的必要信息,下面写的是服务名,添加新的服务的时候,需要重新加载配置文件
*SERVICES
TOUPPER
TOLOWER
HELLOWORLD
编译流程:
0.关闭tuxedo服务
tmshutdown -y
1.修改配置文件,重新加载
tmloadcf -y ubbsimple
2.编译服务程序,(可以放到makefile里面,或者一个脚本里面)
-s后面写的是对应的服务名
buildserver -o aslan -f simpserv.c -s TOUPPER -s TOLOWER -s HELLOWORLD
3.编译client程序
buildclient -o myfirst -f myfirst.c
4.启动tuxedo服务
tmboot -y
5.执行client程序查看效果
./myfirst hello world
代码:
server.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
#include
#include /* TUXEDO Header File */
#include /* 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);
}
#ifdef __cplusplus
extern "C"
#endif
void TOLOWER(TPSVCINFO * rqst)
{
int i;
for(i = 0; i < rqst->len-1; i++)
rqst->data[i] = tolower(rqst->data[i]);
/* Return the transformed buffer to the requestor. */
tpreturn(TPSUCCESS, 0, rqst->data, 0L, 0);
}
#ifdef __cplusplus
extern "C"
#endif
void HELLOWORLD(TPSVCINFO * rqst)
{
sprintf(rqst->data,"%s","hello world");
tpreturn(TPSUCCESS,0,rqst->data,0L,0);
}
myfirst.c
#include
#include "atmi.h"
int main(int argc,char *argv[])
{
char * sendbuf, * recvbuf;
long sendlen,recvlen;
int ret;
if(argc != 2)
{
fprintf(stderr,"参数个数不是两个");
exit(0);
}
if(tpinit((TPINIT *)NULL) == -1)
{
fprintf(stderr,"tpinit failed");
exit(1);
}
sendlen = strlen(argv[1]);
sendbuf = (char *) tpalloc("STRING",NULL,sendlen+1);
recvbuf = (char *)tpalloc("STRING",NULL,sendlen+1);
strcpy(sendbuf,argv[1]);
ret = tpcall("TOUPPER",sendbuf,0,&recvbuf,&recvlen,0);
// ret = tpcall("TOUPPER",(char *)sendbuf,0,(char **)&recvbuf,&recvlen,(long)0);
if(ret == -1)
{
fprintf(stderr,"can not send request to server TOUPPER\n");
fprintf(stderr,"Tperrno = %d\n",tperrno);
tpfree(sendbuf);
tpfree(recvbuf);
tpterm();
exit(1);
}
fprintf(stderr,"Returned string is : %s\n",recvbuf);
tpfree(sendbuf);
tpfree(recvbuf);
tpterm();
return 0;
}