Posted on 2019-01-11 15:53
Prayer 阅读(485)
评论(0) 编辑 收藏 引用 所属分类:
TUXEDO
https://blog.csdn.net/zistxym/article/details/51533774
client.c
=====================================================
#include <stdio.h>
#include "atmi.h" /*包含TUXEDO系统的头文件"atmi.h", 以便引用TUXEDO的函数和变量定义。*/#define ALLOClEN 20000 /*定义输入和返回的长度*/#define MAXLEN 20000 /*定义输入和返回的长度*///读取文件filename的内容到dest数组,最多可以读maxlen个字节//成功返回文件的字节数,失败返回-1int read_file(const char *filename, char *dest, int maxlen){ FILE *file; int pos, temp, i; //打开文件 file = fopen(filename, "r"); if( NULL == file ) { fprintf(stderr, "open %s error\n", filename); return -1; } pos = 0; //循环读取文件中的内容 for(i=0; i<MAXLEN-1; i++) { temp = fgetc(file); if( EOF == temp ) break; dest[pos++] = temp; } //在数组末尾加0 dest[pos] = 0; return pos;}int main(int argc, char** argv){ char *inbuf=NULL; char *outbuf=NULL; long len=0; long outlen=0; char inbuftmp[MAXLEN]=""; char envinfo[100] = ""; sprintf(envinfo, "WSNADDR=//%s",argv[1]); tuxputenv(envinfo); if( argc != 4 ) { fprintf(stderr, "用法: ./client IP:port 服务名 请求报文\n"); fprintf(stderr, "用法示例: ./client 192.168.224.128:2225 sv_query ./test.txt \n"); return -1; } len = read_file(argv[3], inbuftmp, MAXLEN); /*客户端调用tpinit()连接应用*/ if (tpinit((TPINIT * )NULL) == -1) { exit(1); } /*用tpalloc()分配一个STRING类型数据缓冲*/ if (NULL==(outbuf=tpalloc("STRING", NULL, ALLOClEN))) { tpterm(); exit(-1); } /*用tpalloc()分配一个STRING类型数据缓冲*/ if (NULL==(inbuf=tpalloc("STRING", NULL, ALLOClEN))) { tpterm(); exit(2); } /*将"hello world"拷贝进缓冲*/ strcpy(inbuf, inbuftmp); printf("\t请求报文:[%s]\n",inbuf); /*用tpcall()包含数据缓冲,向交易"TOUPPER"发一个同步请求*/ if ( tpcall(argv[2], inbuf, 0, &outbuf, &outlen, 0)== -1) { fprintf(stderr, "service requst fail.\n"); tpfree(inbuf); tpfree(outbuf); tpterm(); exit(-1); } /*打印出改变的数据缓冲*/ printf("\t 应答报文:[%s]\n", outbuf); tpfree(inbuf); tpfree(outbuf); /*调用tpterm()切断与应用的连接*/ tpterm(); exit(0);}
makefile
======================
all:
buildclient -w -f client.c -o client -v
test.txt
=============
<REQ_MSG><HEAD><FUNCID>01</FUNCID><OPUSER></OPUSER><OPROLE>1</OPROLE><OPCHANNEL></OPCHANNEL><OPSITE></OPSITE><SESSION></SESSION><RUNTIME></RUNTIME><RESERVE></RESERVE></HEAD><BODY><APPSHEETSERIALNO></APPSHEETSERIALNO><CERTIFICATETYPE>3</CERTIFICATETYPE><CERTIFICATENO>jg1234我#11111111111111111</CERTIFICATENO><INVESTORNAME>sheny机111</INVESTORNAME><TRANSACTIONDATE>20140909</TRANSACTIONDATE><TRANSACTIONTIME>14</TRANSACTIONTIME><INDIVIDUALORINSTITUTION>0</INDIVIDUALORINSTITUTION><DISTRIBUTORCODE>225</DISTRIBUTORCODE><BUSINESSCODE>001</BUSINESSCODE><CHANNEL>1</CHANNEL><TRANSACTIONACCOUNTID>002</TRANSACTIONACCOUNTID><BRANCHCODE>001</BRANCHCODE><HOLDERCODE>002</HOLDERCODE><MANAGERCODE></MANAGERCODE><CUSTODIANCODE>004</CUSTODIANCODE><CAPITALTYPE>2</CAPITALTYPE><CAPITALFLAG></CAPITALFLAG><INSTREPRTYPE>1</INSTREPRTYPE><INSTREPRFLAG>1</INSTREPRFLAG></BODY></REQ_MSG>