📄 broadcli.c
字号:
#include <stdio.h>#include "atmi.h" /* TUXEDO Header File *//*myfunc must be defined as below,other define is error*/void _TMDLLENTRY myfunc(char *buffer,long len,long flag){ long len2; char buftype[20],subtype[20]; if ((len2=tptypes(buffer,buftype,subtype))<0) { printf("invalid buffer receive;\n"); } else if(!strcmp(buftype,"STRING")) { printf("unsolicited message from server:%s,len=%d,flag=%d\n",buffer); } else printf("cannot printout buffer\n");}#if defined(__STDC__) || defined(__cplusplus)main(int argc, char *argv[])#elsemain(argc, argv)int argc;char *argv[];#endif{ char *sendbuf, *rcvbuf; long sendlen, rcvlen; int ret; int i; TPINIT *tpinfo=NULL;; if(argc != 2) { (void) fprintf(stderr, "Usage: simpcl string\n"); exit(1); } tpinfo =(TPINIT*)tpalloc("TPINIT",NULL,TPINITNEED(0)); if (tpinfo == (TPINIT*)NULL) { fprintf(stderr,"unable to allocate TPINIT buffer\n"); exit(1); } strcpy(tpinfo->usrname,"xcjing"); strcpy(tpinfo->cltname,"xcjclient"); //strcpy(tpinfo->passwd,"isme"); //strcpy(tpinfo->grpname,"xcjgroup"); tpinfo->flags=TPU_DIP;/*TPU_IGN,TPU_DIP,TPU_SIG(the default is TUP_DIP?)*/ //strcpy ((char *)&tpinfo->data, "isme"); //tpinfo->datalen = strlen((char *)&tpinfo->data)+1L; /* Attach to System/T as a Client Process */ if (tpinit(tpinfo) == -1) { (void) fprintf(stderr, "Tpinit failed\n"); exit(1); } sendlen = strlen(argv[1]); /* Allocate STRING buffers for the request and the reply */ if((sendbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) { (void) fprintf(stderr,"Error allocating send buffer\n"); tpterm(); exit(1); } if((rcvbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) { (void) fprintf(stderr,"Error allocating receive buffer\n"); tpfree(sendbuf); tpterm(); exit(1); } printf("@@@@@@@@@\n"); if(tpsetunsol(myfunc)== TPUNSOLERR) { printf("tpsetunsol() failure:%s\n",tpstrerror(tperrno)); tpfree(sendbuf); tpfree(rcvbuf); tpterm(); exit(1); } (void) strcpy(sendbuf, argv[1]); printf("11111111\n"); /* Request the service TOUPPER, waiting for a reply */ ret = tpcall("BROADCAST", (char *)sendbuf, 0, (char **)&rcvbuf, &rcvlen, (long)0); if(ret == -1) { fprintf(stderr, "Can't send request to service TOUPPER:%s\n",tpstrerror(tperrno)); tpfree(sendbuf); tpfree(rcvbuf); tpterm(); exit(1); } printf("111\n"); (void) fprintf(stdout, "Returned string is: %s\n", rcvbuf); if ((i=tpchkunsol())==-1) { printf("tpchkunsol() failed %d\n",tperrno); } else if(i==0) { printf("tpchkunsol() successful but num = %d\n",i); } else { printf("tpchkunsol() successful num = %d\n",i); } printf("222\n"); /* Free Buffers & Detach from System/T */ tpfree(sendbuf); tpfree(rcvbuf); tpterm(); printf("333\n"); return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -