Examples
This chapter describes the roles of SVCGW with examples.
1. NOREPLY Service Call
The following example shows how a Tmax service or client makes a service request to SVCGW through tpacall and processes the request regardless of the result.
The program consists of the following files.
Type | File Name |
---|---|
Environment File |
tmax.m, tcpsvcgw.cfg |
Remote Node |
remote.cc |
1.1. Environment File
< tmax.m >
*DOMAIN res SHMKEY = 88000, MINCLH = 1, MAXCLH = 1, TPORTNO = 8888 *NODE node1 TMAXDIR=”/home/tmax”, APPDIR=”/home/tmax/appbin” *SVRGROUP svg1 NODENAME = node1 *SERVER tcpsvcgw SVGNAME = svg1, MIN=1, MAX=1, CPC=10, SVRTYPE=CUSTOM_GATEWAY, CLOPT=”-- -P 8090 -F /home/tmax/config/tcpsvcgw.cfg –N 20” svr SVGNAME = svg1, MIN=1, MAX=1 *SERVICE TCPSVC1 SVRNAME = tcpsvcgw TOUPPER SVRNAME = svr
< tcpsvcgw.cfg >
####################################################### # TCP/IP Service Gateway Config # ####################################################### # gwno ipaddr Tmaxsvc # 0 1.1.1.1 SVC ####################################################### # line start with "#" is comment line # gwno must start at 0 and be increased by 1 # ipaddr: remote node ipaddr # svc: tmax service name ####################################################### 0 1.1.1.1 TCPSVC1
1.2. Remote Node
< toupper.c >
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <usrinc/atmi.h> main(int argc, char *argv[]) { char *sndbuf, *rcvbuf; long rcvlen; if (argc != 2) { printf("Usage: toupper string\n"); exit(1); } if (tpstart((TPSTART_T *)NULL) == -1){ printf("Tpstart failed\n"); exit(1); } if ((sndbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL) { printf("Sendbuf alloc failed !\n"); tpend(); exit(1); } if ((rcvbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL) { printf("Recvbuf alloc failed !\n"); tpfree((char *)sndbuf); tpend(); exit(1); } strcpy(sndbuf, argv[1]); if(tpcall("TOUPPER", sndbuf, 0, &rcvbuf, &rcvlen, 0)==-1){ printf("Can't send request to service TOUPPER\n"); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); exit(1); } printf("Sendbuf data: %s\n", sndbuf); printf("Recvbuf data: %s\n", rcvbuf); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); }
< svr.c >
#include <stdio.h> #include <usrinc/atmi.h> TOUPPER(TPSVCINFO *msg) { char *sndbuf; long sndlen; if ((sndbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL) { printf("sendbuf alloc failed !\n"); tpreturn(TPFAIL, -1, NULL, 0, 0); } strcpy(sndbuf, msg->data); sndlen = msg->len; /* Remote TCPSVC1 service call */ if(tpacall("TCPSVC1", sndbuf, sndlen, TPNOREPLY)==-1){ printf("Can't send request to service TCPSVC1\n"); tpfree((char *)sndbuf); tpreturn(TPFAIL, -1, NULL, 0, 0 ); } tpfree((char *)sndbuf); tpreturn(TPSUCCESS,0,(char *)msg->data, msg->len,0); }
< remote.c >
#include <stdio.h> #include <winsock2.h> #include <usrinc/commhead.h> #define SVR_PORT "1.1.1.1:8090" int main(int argc, char *argv[]) { int n, msgtype; long ilen, olen; char buffer[1024]; char svcname[24]; /* Register the remote node to the Gateway */ printf("Remote Service Start...\n\n"); n = ComOpen(TCPIP, NULL, SVR_PORT ); if (n < 0) { perror("Gateway register error:"); return -1; } while(1) { memset(svcname, 0x00, sizeof(svcname)); memset(buffer, 0x00, sizeof(buffer)); /* Receive data. */ n = ComRecv(svcname, &msgtype, buffer, &olen, COMMNOFLAG); if (n < 0) { perror("Data Receive error:"); ComClose(); return -1; } printf("REMOTE RECV : svcname = [%s]\n", svcname); printf("REMOTE RECV : len = %d\n",olen); printf("REMOTE RECV : data= [%s]\n\n", buffer); } /* Disconnect from the gateway. */ ComClose( ); }
2. REPLY Service Call
In this example, a Tmax service or client makes a request to SVCGW through tpacall and processes it regardless of the result. The remote node calls the TOLOWER function to process the result from another service on Tmax.
The program consists of the following files.
Type | File Name |
---|---|
Environment File |
tmax.m, tcpsvcgw.cfg |
Remote Node |
remote.c |
2.1. Environment File
< tmax.m >
*DOMAIN Res SHMKEY = 88000, MINCLH = 1, MAXCLH = 1, TPORTNO = 8888 *NODE node1 TMAXDIR=”/home/tmax”, APPDIR=”/home/tmax/appbin” *SVRGROUP svg1 NODENAME = node1 *SERVER tcpsvcgw SVGNAME = svg1, MIN=1, MAX=1, CPC=10, SVRTYPE=CUSTOM_GATEWAY, CLOPT=”-- -P 8090 -F /home/tmax/config/tcpsvcgw.cfg –N 20” svr SVGNAME = svg1, MIN=1, MAX=1, *SERVICE TCPSVC1 SVRNAME = tcpsvcgw TOUPPER SVRNAME = svr TOLOWER SVRNAME = svr
< tcpsvcgw.cfg >
####################################################### # TCP/IP Service Gateway Config # ####################################################### # gwno ipaddr Tmaxsvc # 0 1.1.1.1 SVC ####################################################### # line start with "#" is comment line # gwno must start at 0 and be increased by 1 # ipaddr: remote node ipaddr # svc: tmax service name ####################################################### 0 1.1.1.1 TCPSVC1
2.2. Remote Node
< toupper.c >
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <usrinc/atmi.h> main(int argc, char *argv[]) { char *sndbuf, *rcvbuf; long rcvlen; if (argc != 2) { printf("Usage: toupper string\n"); exit(1); } if (tpstart((TPSTART_T *)NULL) == -1){ printf("Tpstart failed\n"); exit(1); } if ((sndbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL) { printf("Sendbuf alloc failed !\n"); tpend(); exit(1); } if ((rcvbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL) { printf("Recvbuf alloc failed !\n"); tpfree((char *)sndbuf); tpend(); exit(1); } strcpy(sndbuf, argv[1]); if(tpcall("TOUPPER", sndbuf, 0, &rcvbuf, &rcvlen, 0)==-1){ printf("Can't send request to service TOUPPER\n"); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); exit(1); } printf("Sendbuf data: %s\n", sndbuf); printf("Recvbuf data: %s\n", rcvbuf); tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); }
< svr.c >
#include <stdio.h> #include <usrinc/atmi.h> TOUPPER(TPSVCINFO *msg) { char *sndbuf; long sndlen; if ((sndbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL) { printf("sendbuf alloc failed !\n"); tpreturn(TPFAIL, -1, NULL, 0, 0); } strcpy(sndbuf, msg->data); sndlen = msg->len; if(tpacall("TCPSVC1", sndbuf, sndlen, TPNOREPLY)==-1){ printf("Can't send request to service TCPSVC1\n"); tpfree((char *)sndbuf); tpreturn(TPFAIL, -1, NULL, 0, 0 ); } tpfree((char *)sndbuf); tpreturn(TPSUCCESS,0,(char *)msg->data, msg->len,0); } TOLOWER(TPSVCINFO *msg) { int i; printf("TOLOWER service is started!\n"); printf("INPUT : data=%s\n", msg->data); for (i = 0; i < msg->len; i++) msg->data[i] = tolower(msg->data[i]); printf("OUTPUT: data=%s\n\n", msg->data); tpreturn(TPSUCCESS,0,(char *)msg->data, 0,0); }
< remote.c >
#include <stdio.h> #include <winsock2.h> #include <usrinc/commhead.h> #define SVR_PORT "1.1.1.1:8090" int main(int argc, char *argv[]) { int n, msgtype; long ilen, olen; char buffer[1024]; char svcname[24]; /* Register the remote node to the gateway. */ printf("Remote Service Start...\n\n"); n = ComOpen(TCPIP, "TCPSVC1", SVR_PORT ); if (n < 0) { perror("Gateway register error:"); return -1; } while(1) { memset(svcname, 0x00, sizeof(svcname)); memset(buffer, 0x00, sizeof(buffer)); /* Receive data. */ n = ComRecv(svcname, &msgtype, buffer, &olen, COMMNOFLAG); if (n < 0) { perror("Data Receive error:"); ComClose(); return -1; } printf("REMOTE RECV : svcname = [%s]\n", svcname); printf("REMOTE RECV : len = %d\n",olen); printf("REMOTE RECV : data= [%s]\n\n", buffer); /* Send the reply data. */ strcpy(buffer,"I'M REMOTE SERVICE."); ilen = strlen(buffer) + 1; n = ComSend("TOLOWER", COMMDATA, buffer, ilen, COMMNOREPLY); if (n < 0) { perror("Data send error:"); ComClose(); return -1; } } /* Disconnect from the gateway. */ ComClose( ); }
3. Remote Synchronous Call
In this example, SVCGW, which starts during Tmax startup, receives a request from a remote node, calls the user-specified service, and sends the processing result to the remote node.
The program consists of the following files.
Type | File Name |
---|---|
Environment File |
tmax.m, tcpsvcgw.cfg |
Remote Node |
remote.c |
3.1. Environment File
< tmax.m >
*DOMAIN Res SHMKEY = 88000, MINCLH = 1, MAXCLH = 1, TPORTNO = 8888 *NODE node1 TMAXDIR=”/home/tmax”, APPDIR=”/home/tmax/appbin” *SVRGROUP svg1 NODENAME = node1 *SERVER tcpsvcgw SVGNAME = svg1, MIN=1, MAX=1, CPC=10, SVRTYPE=CUSTOM_GATEWAY, CLOPT=”-- -P 8090 -F /home/tmax/config/tcpsvcgw.cfg –N 20” svr SVGNAME = svg1, MIN=1, MAX=1 *SERVICE TCPSVC1 SVRNAME = tcpsvcgw TOUPPER SVRNAME = svr
< tcpsvcgw.cfg >
####################################################### # TCP/IP Service Gateway Config # ####################################################### # gwno ipaddr Tmaxsvc # 0 1.1.1.1 SVC ####################################################### # line start with "#" is comment line # gwno must start at 0 and be increased by 1 # ipaddr: remote node ipaddr # svc: tmax service name ####################################################### 0 1.1.1.1 TCPSVC1
3.2. Remote Node
< svr.c >
#include <stdio.h> #include <usrinc/atmi.h> TOUPPER(TPSVCINFO *msg) { int i; char *sndbuf; printf("TOUPPER service is started!\n"); printf("INPUT : data=%s, len = %d\n", msg->data, msg->len); for (i = 0; i < msg->len; i++) msg->data[i] = toupper(msg->data[i]); printf("OUTPUT: data=%s, len = %d\n", msg->data, msg->len); tpreturn(TPSUCCESS,0,(char *)msg->data, msg->len,0); }
< remote.c >
#include <stdio.h> #include <winsock2.h> #include <usrinc/commhead.h> #define SVR_PORT "1.1.1.1:8090" int main(int argc, char *argv[]) { int n, msgtype; long ilen, olen; char buffer[1024]; char svcname[20]; char *ptr; /* Register the remote node to the gateway. */ printf("Remote Service Start...\n\n"); n = ComOpen(TCPIP,"TCPSVC1", SVR_PORT); if (n < 0) { perror("Gateway register error:"); return -1; } ptr = argv[1]; ilen = strlen(argv[1]) + 1; printf("Send Data = [%s], len = %d\n",ptr,ilen); n = ComSend("TOUPPER", COMMDATA, ptr, ilen, COMMNOFLAG); if (n < 0) { perror("Data send error:"); ComClose(); return -1; } memset(svcname, 0x00, sizeof(svcname)); memset(buffer, 0x00, sizeof(buffer)); /* Receive the reply data. */ n = ComRecv(svcname, &msgtype, buffer, &olen, COMMNOFLAG); if (n < 0) { perror("Data Receive error:"); ComClose(); return -1; } printf("REMOTE RECV : svcname = [%s]\n", svcname); printf("REMOTE RECV : len = %d\n",olen); printf("REMOTE RECV : data= [%s]\n\n", buffer); /* Disconnect from the gateway. */ ComClose( ); }
4. ACK/NAK Communication Method
In this example, SVCGW, which starts during Tmax startup, receives a request from a remote node, calls the user-specified service, and sends the processing result to the remote node. This example also includes ACK/NAK processing for the transmitted data.
The program consists of the following files.
Type | File Name |
---|---|
Environment File |
tmax.m, tcpsvcgw.cfg |
Remote Node |
remote.c |
4.1. Environment File
< tmax.m >
*DOMAIN res SHMKEY = 88000, MINCLH = 1, MAXCLH = 1, TPORTNO = 8888 *NODE node1 TMAXDIR=”/home/tmax”, APPDIR=”/home/tmax/appbin” *SVRGROUP svg1 NODENAME = node1 *SERVER tcpsvcgw SVGNAME = svg1, MIN=1, MAX=1, CPC=10, SVRTYPE=CUSTOM_GATEWAY, CLOPT=”-- -P 8090 -F /home/tmax/config/tcpsvcgw.cfg –N 20 -A” svr SVGNAME = svg1, MIN=1, MAX=1 *SERVICE COM1 SVRNAME = tcpsvcgw TOUPPER SVRNAME = svr
< tcpsvcgw.cfg >
####################################################### # TCP/IP Service Gateway Config # ####################################################### # gwno ipaddr Tmaxsvc # 0 1.1.1.1 SVC ####################################################### # line start with "#" is comment line # gwno must start at 0 and be increased by 1 # ipaddr: remote node ipaddr # svc: tmax service name ####################################################### 0 1.1.1.1 TCPSVC1
4.2. Remote Node
< svr.c >
#include <stdio.h> #include <usrinc/atmi.h> TOUPPER(TPSVCINFO *msg) { int i; char *sndbuf; printf("TOUPPER service is started!\n"); printf("INPUT : data=%s, len = %d\n", msg->data, msg->len); for (i = 0; i < msg->len; i++) msg->data[i] = toupper(msg->data[i]); printf("OUTPUT: data=%s, len = %d\n", msg->data, msg->len); tpreturn(TPSUCCESS,0,(char *)msg->data, msg->len,0); }
< remote.c >
#include <stdio.h> #include <winsock2.h> #include <usrinc/commhead.h> #define SVR_PORT "1.1.1.1:8090" int main(int argc, char *argv[]) { int n, msgtype; long ilen, olen; char buffer[1024]; char svcname[20]; char *ptr; /* Register the remote node to the gateway. */ printf("Remote Service Start...\n\n"); n = ComOpen(TCPIP,"TCPSVC1", SVR_PORT); if (n < 0) { perror("Gateway register error:"); return -1; } while(1) { ptr = argv[1]; ilen = strlen(argv[1]) + 1; printf("Send Data = [%s], len = %d\n",ptr,ilen); n = ComSend("TOUPPER", COMMDATA, ptr, ilen, COMMNOFLAG); if (n < 0) { perror("Data send error:"); ComClose(); return -1; } memset(svcname, 0x00, sizeof(svcname)); memset(buffer, 0x00, sizeof(buffer)); /* Receive ACK/NAK. */ n = ComRecv(svcname, &msgtype, buffer, &olen, COMMNOFLAG); if (n < 0) { perror("Data Receive error:"); ComClose(); return -1; } if (msgtype == COMMACK) break; } printf("REMOTE RECV : msgtype = %d\n\n",msgtype); memset(svcname, 0x00, sizeof(svcname)); memset(buffer, 0x00, sizeof(buffer)); /* Receive the reply data. */ n = ComRecv(svcname, &msgtype, buffer, &olen, COMMNOFLAG); if (n < 0) { perror("Data Receive error:"); ComClose(); return -1; } /* Receive ACK/NAK. */ n = ComSend("TOUPPER", COMMACK, NULL, 0, COMMNOFLAG); if (n < 0) { perror("Data send error:"); ComClose(); return -1; } printf("REMOTE RECV : svcname = [%s]\n", svcname); printf("REMOTE RECV : len = %d\n",olen); printf("REMOTE RECV : data= [%s]\n\n", buffer); /* Disconnect from the gateway. */ ComClose( ); }