tuxedo 会话通信 运行失败
服务器端源程序:#include<stdio.h>#include<string.h>
#include<stdlib.h>
#include"atmi.h"
#include"viewrecord.h"
#define MXSTR 80
static struct viewrecord* bufptr;
int tpsvrinit(int argc,char* argv[]){
bufptr=(struct viewrecord*)tpalloc("VIEW32","viewrecord",sizeof(struct viewrecord));
return 0;
}
void GETRECORDS(TPSVCINFO* msg){
long len,revent;
int cd;
FILE *file;
char *error,input;
cd=msg->cd;
file=fopen("customerinfo.data","r");
while((error=fgets(input,80,file))!=NULL){
strcpy(bufptr->f_name,strtok(input," "));
strcpy(bufptr->l_name,strtok(NULL," "));
strcpy(bufptr->address,strtok(NULL," "));
strcpy(bufptr->city,strtok(NULL," "));
strcpy(bufptr->state,strtok(NULL,""));
strcpy(bufptr->zipcode,strtok(NULL," "));
if(tpsend(cd,(char*)bufptr,0,TPSIGRSTRT,&revent)==-1){
userlog("serverconv tpsend receive an unexpected event\n");
tpreturn(TPFAIL,0,(char*)bufptr,0,0);
}
}
fclose(file);
tpreturn(TPSUCCESS,0,NULL,0L,0);
}
void tpsvrdone(){
tpfree((char*)bufptr);
}
客户端程序:
#include<stdio.h>
#include<stdlib.h>
#include"atmi.h"
#include"viewrecord.h"
int main(int argc,char* argv[]){
int cd,recvlen,ret/*,revent*/;
long revent;
struct viewrecord *bufptr;
tpinit((TPINIT*)NULL);
if((cd=tpconnect("GETRECORDS",(char*)NULL,0,TPRECVONLY))==-1){
fprintf(stderr,"tpconnect:%s\n",tpstrerror(tperrno));
exit(1);
}
if((bufptr=(struct viewrecord*)tpalloc("VIEW32","viewrecord",sizeof(struct viewrecord)))==NULL){
fprintf(stderr,"tpalloc for VIEW32 failed!\n");
tpterm();
}
while(1){
if((ret=tprecv(cd,(char**)&bufptr,(long*)&recvlen,TPSIGRSTRT,(long*)&revent))==-1)
if(revent==TPEV_SVCSUCC)
break;
else
tpdiscon(cd);
printf("NAME:%s %s\nADDRESS:%s\nCity/State/Zip:%s,%s,%s\n\n",bufptr->f_name,bufptr->l_name,
bufptr->address,bufptr->city,bufptr->state,bufptr->zipcode);
}
tpfree((char*)bufptr);
tpterm();
fprintf(stderr,"----The End!----\n");
return 0;
}
客户端运行结果:
$ ./convclient
NAME:#firstname lastname
ADDRESS:address
City/State/Zip:city,state,zipcode
NAME:jon smith
ADDRESS:123 allen rode
City/State/Zip:san jose,NJ,07938
之后一直输出
NAME:jon smith
ADDRESS:123 allen rode
City/State/Zip:san jose,NJ,07938
NAME:jon smith
ADDRESS:123 allen rode
City/State/Zip:san jose,NJ,07938
NAME:jon smith
ADDRESS:123 allen rode
City/State/Zip:san jose,NJ,07938
.......
不知道哪位大侠知道是哪个地方出错了,求指导 死循环了,看看 客户端程序里,while loop那个部分 if break部分是否有效。
嗯,是这样,貌似服务器端tpreturn(TPSUCCESS,...),客户端没有收到,我尝试了去掉中间的数据发送部分,单单进行tpreturn(TPSUCCESS,...),客户端是可以正常结束的,所以我怀疑是不是tpsend的使用方法不当,我刚接触tuxedo不久,希望版主不吝赐教回复 2# rdcwayx
这个问题搞定了,是数据问题,和程序无关,特此结贴
页:
[1]