tuxedo-客户端-服务器程序范例.doc

上传人:豆**** 文档编号:17421664 上传时间:2022-05-24 格式:DOC 页数:8 大小:155.50KB
返回 下载 相关 举报
tuxedo-客户端-服务器程序范例.doc_第1页
第1页 / 共8页
tuxedo-客户端-服务器程序范例.doc_第2页
第2页 / 共8页
点击查看更多>>
资源描述

《tuxedo-客户端-服务器程序范例.doc》由会员分享,可在线阅读,更多相关《tuxedo-客户端-服务器程序范例.doc(8页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、【精品文档】如有侵权,请联系网站删除,仅供学习与交流tuxedo-客户端-服务器程序范例.精品文档.Tpinit /传递客户认证信息Tpalloc /申请缓冲区Tpcall /调用服务Tpfree/释放指向缓冲区的指针Tpsvrinit/服务启动前的一个初始化Tpsvrdone/关闭服务之前自动调用Tpreturn /响应后返回信息char *tpalloc(char *type,char *subtype,long size)Type 用于指定缓冲区类型,可取值STRING FML XML等Subtype 用于指定缓冲区子类型,仅在分配VIEW缓冲区时,指定对应的C结构名,对于其它缓冲区来说

2、,填NULLSize 是缓冲区大小,以字节为单位,如1024表示分配1KB缓冲区Tpalloc 返还分配缓冲区的指针,返还NULL标识分配失败void tpfree(char *ptr)Ptr是要释放的缓冲区的指针Tpfree没有返还值,也就是说不用判断它是否成功的释放了缓冲区int tpcall(char *svc,char *idata,long ilen,char *odata,long *olen,long flags)Svc 是要调用的服务名Idata 是请求缓冲区指针,ilen是请求缓冲区长度Odata 是指向响应缓冲区指针的指针,使用双重指针的目的是便于动态调整响应缓冲区的大小C

3、lient:/*(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(#) sample

4、s/atmi/simpapp/simpcl.c$Revision: 1.5 $ */#include #include atmi.h/* TUXEDO Header File */#if defined(_STDC_) | defined(_cplusplus)main(int argc, char *argv)#elsemain(argc, argv)int argc;char *argv;#endifchar *sendbuf, *rcvbuf;long sendlen, rcvlen;int ret;if(argc != 2) (void) fprintf(stderr, Usage:

5、simpcl stringn);exit(1);/* Attach to System/T as a Client Process */向服务器传递客户认证信息if (tpinit(TPINIT *) NULL) = -1) (void) fprintf(stderr, Tpinit failedn);exit(1);sendlen = strlen(argv1);/* Allocate STRING buffers for the request and the reply */分配缓冲区if(sendbuf = (char *) tpalloc(STRING, NULL, sendlen+

6、1) = NULL) (void) fprintf(stderr,Error allocating send buffern);tpterm();exit(1);if(rcvbuf = (char *) tpalloc(STRING, NULL, sendlen+1) = NULL) (void) fprintf(stderr,Error allocating receive buffern);tpfree(sendbuf);/释放指向缓冲区的指针tpterm();exit(1);(void) strcpy(sendbuf, argv1);/* Request the service TOUP

7、PER, waiting for a reply */调用服务ret = tpcall(TOUPPER, (char *)sendbuf, 0, (char *)&rcvbuf, &rcvlen, (long)0);if(ret = -1) (void) fprintf(stderr, Cant send request to service TOUPPERn);(void) fprintf(stderr, Tperrno = %dn, tperrno);tpfree(sendbuf);tpfree(rcvbuf);tpterm();exit(1);(void) fprintf(stdout,

8、 Returned string is: %sn, rcvbuf);/* Free Buffers & Detach from System/T */tpfree(sendbuf);tpfree(rcvbuf);tpterm();return(0);服务端常用函数简介int tpsvrinit(int argc,char *argv)TUXEDO服务在启动过程中要经历一个初始化阶段,这个时候服务回调tpsvrinit()方法进行全局初始化,它类似于C+的构造函数,给程序员提供了一个打开全局资源(数据库,消息队列,文件系统,socket)和初始化全局变量的好机会int tpsvrdone(voi

9、d)对应tpsvrinit,在关闭服务时被自动调用,类似C+的析构函数,释放初始化打开的资源void tpreturn(int rval,long rcode,char *data,long len,long flags)Data 是要返回的类型缓冲区指针,len是缓冲区的长度Flags 是标志位,目前尚未启用,必须置为0Rcode是用户自定义的整数,可以随tpreturn()一起返回,客户机通过全局变量tpurcode来得到这个值Rval 是服务处理状态位,不用关注int userlog(char *formatarg)此函数和printf的用法一致,服务端可以用此函数记录日志,存放在ULO

10、G.mmddyy文件中,不建议这样使用,TUXEDO每天会自动生成系统日志放在ULOG.mmddyyServer:/*(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

11、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 f

12、unction. 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 arent used. */argc = argc;argv

13、= 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;#endifint i;for(i = 0; i len-1; i+)rqst-datai = toupper(rqst-datai);/* Return the transformed buffer to the requestor. */tpreturn(TPSUCCESS, 0, rqst-data, 0L, 0) ;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 小学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com