tuxedo-客户端-服务器程序范例说课讲解.doc

上传人:1595****071 文档编号:86304066 上传时间:2023-04-14 格式:DOC 页数:15 大小:487KB
返回 下载 相关 举报
tuxedo-客户端-服务器程序范例说课讲解.doc_第1页
第1页 / 共15页
tuxedo-客户端-服务器程序范例说课讲解.doc_第2页
第2页 / 共15页
点击查看更多>>
资源描述

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

1、Good is good, but better carries it.精益求精,善益求善。tuxedo-客户端-服务器程序范例-Tpinit/传递客户认证信息Tpalloc/申请缓冲区Tpcall/调用服务Tpfree/释放指向缓冲区的指针Tpsvrinit/服务启动前的一个初始化Tpsvrdone/关闭服务之前自动调用Tpreturn/响应后返回信息char*tpalloc(char*type,char*subtype,longsize)Type用于指定缓冲区类型,可取值STRINGFMLXML等Subtype用于指定缓冲区子类型,仅在分配VIEW缓冲区时,指定对应的C结构名,对于其它缓冲

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

3、2003BEASystems,Inc.AllRightsReserved.*/*Copyright(c)1997BEASystems,Inc.AllrightsreservedTHISISUNPUBLISHEDPROPRIETARYSOURCECODEOFBEASystems,Inc.Thecopyrightnoticeabovedoesnotevidenceanyactualorintendedpublicationofsuchsourcecode.*/*#ident(#)samples/atmi/simpapp/simpcl.c$Revision:1.5$*/#include#includ

4、eatmi.h/*TUXEDOHeaderFile*/#ifdefined(_STDC_)|defined(_cplusplus)main(intargc,char*argv)#elsemain(argc,argv)intargc;char*argv;#endifchar*sendbuf,*rcvbuf;longsendlen,rcvlen;intret;if(argc!=2)(void)fprintf(stderr,Usage:simpclstringn);exit(1);/*AttachtoSystem/TasaClientProcess*/向服务器传递客户认证信息if(tpinit(TP

5、INIT*)NULL)=-1)(void)fprintf(stderr,Tpinitfailedn);exit(1);sendlen=strlen(argv1);/*AllocateSTRINGbuffersfortherequestandthereply*/分配缓冲区if(sendbuf=(char*)tpalloc(STRING,NULL,sendlen+1)=NULL)(void)fprintf(stderr,Errorallocatingsendbuffern);tpterm();exit(1);if(rcvbuf=(char*)tpalloc(STRING,NULL,sendlen+

6、1)=NULL)(void)fprintf(stderr,Errorallocatingreceivebuffern);tpfree(sendbuf);/释放指向缓冲区的指针tpterm();exit(1);(void)strcpy(sendbuf,argv1);/*RequesttheserviceTOUPPER,waitingforareply*/调用服务ret=tpcall(TOUPPER,(char*)sendbuf,0,(char*)&rcvbuf,&rcvlen,(long)0);if(ret=-1)(void)fprintf(stderr,Cantsendrequesttoser

7、viceTOUPPERn);(void)fprintf(stderr,Tperrno=%dn,tperrno);tpfree(sendbuf);tpfree(rcvbuf);tpterm();exit(1);(void)fprintf(stdout,Returnedstringis:%sn,rcvbuf);/*FreeBuffers&DetachfromSystem/T*/tpfree(sendbuf);tpfree(rcvbuf);tpterm();return(0);服务端常用函数简介inttpsvrinit(intargc,char*argv)TUXEDO服务在启动过程中要经历一个初始化

8、阶段,这个时候服务回调tpsvrinit()方法进行全局初始化,它类似于C+的构造函数,给程序员提供了一个打开全局资源(数据库,消息队列,文件系统,socket)和初始化全局变量的好机会inttpsvrdone(void)对应tpsvrinit,在关闭服务时被自动调用,类似C+的析构函数,释放初始化打开的资源voidtpreturn(intrval,longrcode,char*data,longlen,longflags)Data是要返回的类型缓冲区指针,len是缓冲区的长度Flags是标志位,目前尚未启用,必须置为0Rcode是用户自定义的整数,可以随tpreturn()一起返回,客户机通

9、过全局变量tpurcode来得到这个值Rval是服务处理状态位,不用关注intuserlog(char*formatarg)此函数和printf的用法一致,服务端可以用此函数记录日志,存放在ULOG.mmddyy文件中,不建议这样使用,TUXEDO每天会自动生成系统日志放在ULOG.mmddyyServer:/*(c)2003BEASystems,Inc.AllRightsReserved.*/*Copyright(c)1997BEASystems,Inc.AllrightsreservedTHISISUNPUBLISHEDPROPRIETARYSOURCECODEOFBEASystems,I

10、nc.Thecopyrightnoticeabovedoesnotevidenceanyactualorintendedpublicationofsuchsourcecode.*/*#ident(#)samples/atmi/simpapp/simpserv.c$Revision:1.5$*/#include#include#include/*TUXEDOHeaderFile*/#include/*TUXEDOHeaderFile*/*tpsvrinitisexecutedwhenaserverisbooted,beforeitbeginsprocessingrequests.Itisnotn

11、ecessarytohavethisfunction.Alsoavailableistpsvrdone(notusedinthisexample),whichiscalledatservershutdowntime.*/#ifdefined(_STDC_)|defined(_cplusplus)tpsvrinit(intargc,char*argv)#elsetpsvrinit(argc,argv)intargc;char*argv;#endif/*Somecompilerswarnifargcandargvarentused.*/argc=argc;argv=argv;/*userlogwr

12、itestothecentralTUXEDOmessagelog*/userlog(Welcometothesimpleserver);return(0);/*Thisfunctionperformstheactualservicerequestedbytheclient.Itsargumentisastructurecontainingamongotherthingsapointertothedatabuffer,andthelengthofthedatabuffer.*/#ifdef_cplusplusexternC#endifvoid#ifdefined(_STDC_)|defined(_cplusplus)TOUPPER(TPSVCINFO*rqst)#elseTOUPPER(rqst)TPSVCINFO*rqst;#endifinti;for(i=0;ilen-1;i+)rqst-datai=toupper(rqst-datai);/*Returnthetransformedbuffertotherequestor.*/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