Posted on 2019-01-11 15:53
Prayer 閱讀(515)
評(píng)論(0) 編輯 收藏 引用 所屬分類(lèi):
TUXEDO
https://blog.csdn.net/zistxym/article/details/51533774
client.c
=====================================================
#include <stdio.h>
#include "atmi.h" /*包含TUXEDO系統(tǒng)的頭文件"atmi.h", 以便引用TUXEDO的函數(shù)和變量定義。*/#define ALLOClEN 20000 /*定義輸入和返回的長(zhǎng)度*/#define MAXLEN 20000 /*定義輸入和返回的長(zhǎng)度*///讀取文件filename的內(nèi)容到dest數(shù)組,最多可以讀maxlen個(gè)字節(jié)//成功返回文件的字節(jié)數(shù),失敗返回-1int read_file(const char *filename, char *dest, int maxlen){ FILE *file; int pos, temp, i; //打開(kāi)文件 file = fopen(filename, "r"); if( NULL == file ) { fprintf(stderr, "open %s error\n", filename); return -1; } pos = 0; //循環(huán)讀取文件中的內(nèi)容 for(i=0; i<MAXLEN-1; i++) { temp = fgetc(file); if( EOF == temp ) break; dest[pos++] = temp; } //在數(shù)組末尾加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 服務(wù)名 請(qǐng)求報(bào)文\n"); fprintf(stderr, "用法示例: ./client 192.168.224.128:2225 sv_query ./test.txt \n"); return -1; } len = read_file(argv[3], inbuftmp, MAXLEN); /*客戶(hù)端調(diào)用tpinit()連接應(yīng)用*/ if (tpinit((TPINIT * )NULL) == -1) { exit(1); } /*用tpalloc()分配一個(gè)STRING類(lèi)型數(shù)據(jù)緩沖*/ if (NULL==(outbuf=tpalloc("STRING", NULL, ALLOClEN))) { tpterm(); exit(-1); } /*用tpalloc()分配一個(gè)STRING類(lèi)型數(shù)據(jù)緩沖*/ if (NULL==(inbuf=tpalloc("STRING", NULL, ALLOClEN))) { tpterm(); exit(2); } /*將"hello world"拷貝進(jìn)緩沖*/ strcpy(inbuf, inbuftmp); printf("\t請(qǐng)求報(bào)文:[%s]\n",inbuf); /*用tpcall()包含數(shù)據(jù)緩沖,向交易"TOUPPER"發(fā)一個(gè)同步請(qǐng)求*/ if ( tpcall(argv[2], inbuf, 0, &outbuf, &outlen, 0)== -1) { fprintf(stderr, "service requst fail.\n"); tpfree(inbuf); tpfree(outbuf); tpterm(); exit(-1); } /*打印出改變的數(shù)據(jù)緩沖*/ printf("\t 應(yīng)答報(bào)文:[%s]\n", outbuf); tpfree(inbuf); tpfree(outbuf); /*調(diào)用tpterm()切斷與應(yīng)用的連接*/ 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機(jī)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>