題目:想使用 TCPIP LISTNER ,去當 TCPIP Concurrent server. 然後再去執行

           TCPIP server 程式,這隻TCPIP server 程式再passend to Pathway server.

           TCPIP program 要收的電文是

           pathwaymon(5 bytes) +pathway_servername(8 bytes) +data(變動長度)

        e.g .pathmon name  $GSCU, pathway serverclass name = mersvrao,data=xxxxx

           電文 =$GSCUMERSVRAOxxxxxxx ,

The flow is :

1.設定TCPIP LISTNER ,它會讀取 $SYSTEM.ZTCPIP.PORTCONF

$SYSTEM.ZTCPIP.PORTCONF

 # add port 15002 for test program started by LISTNER

 15002     $dev.raytcp.svrln2o

2.使用 super.super 去 restart TCPIP LISTNER

$SYSTEM HP 27> Delete DEFINE =TCPIP^PROCESS^Name

$SYSTEM HP 28> ADD    DEFINE =TCPIP^PROCESS^NAME,  FILE $ZB01F

$SYSTEM HP 29> PARAM          TCPIP^PROCESS^NAME $ZB01F

$SYSTEM HP 30> PARAM ZTNT^TRANSPORT^PROCESS^NAME $ZB01F

$SYSTEM HP 31> LISTNER /CPU 1, TERM $ZHOME, NAME $ZP01F, PRI 150, NOWAIT/

3. SVRLN2 程式(TCPIP server program)

#include <socket.h>

#include <in.h>

#include <netdb.h>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <fcntl.h>

#include <cextdecs(SERVERCLASS_SEND_,SERVERCLASS_SEND_INFO_)>

char  pmonname[] = "$GSCU";

char  servername[] = "MERSVRAO";

char  serverbuf[20]= "0001003132000163";

short count_read;

int   error;

int   serverbuf_size;

int   i;

/*

 *

 error = SERVERCLASS_SEND_ (pmonname              // pathmon-process-name

                       ,(short)strlen(pmonname)   // pathmon-process-name-len

                       ,servername                // server-class-name

                       ,(short)strlen(servername) // server-class-name-len

                       ,serverbuf                 // message-buffer

                       ,16                        // request-len

                       ,(short)strlen(buf)        // maximum-reply-len

                       ,&count_read               // actual-reply-len

                       );

*/

int Accept_Conn(char*);

int sock = -1;

int main(int argc, char *argv[])

{

        int nrcvd;

        char buf[1024], *cp;

        FILE *outfile;

        /*

        * If this has been started by a server, then

        * accept a connection; otherwise, echo to

        * stdout from stdin.

        */

if (argv[1] != (char *)NULL) {

        /*

        * argv[1] must have port.hostname format.

        */

        if ((cp = strchr(argv [1], '.')) == (char *)NULL) {

                fprintf(stderr, "Server: bad arg %s\n", argv[1]);

                exit(1);

        }

        *cp = 0;

        if (atoi(argv[1]) == 0) {

                fprintf(stderr, "Server: bad arg %s\n", argv[1]);

                exit(1);

        }

        *cp = '.';

        if (Accept_Conn(argv[1]) == 0)

                exit(1);

}

if (sock >= 0)

    while ((nrcvd = recv(sock, buf, (int)sizeof(buf), 0)) > 0){

            /* send(sock, buf, nrcvd, 0); */

            /* outfile = fopen("$dev.raytcp.log","w");   */

            /* buf structure =

                pathway_name(5)+pathway_servername(8)+data */

            for (i=0;i<5;i++)         /* copy pmonname */

                pmonname[i]=buf[i];

            for (i=0;i<8;i++)        /* copy servername */

                servername[i] = buf[i+5];

            serverbuf_size =(int)sizeof(buf) - 13;

            for (i=0;i<serverbuf_size;i++)

                serverbuf[i] = buf[i+13];

            error = SERVERCLASS_SEND_ (pmonname

                                       ,(short)strlen(pmonname)

                                       ,servername

                                       ,(short)strlen(servername)

                                       ,serverbuf

                                       ,serverbuf_size

                                       ,(short)strlen(serverbuf)

                                       ,&count_read

                                       );

            send(sock,serverbuf,nrcvd, 0);

            /*  fclose(outfile);    */

         }

else

    while ((nrcvd = read(fileno(stdin), buf, (int)sizeof(buf))) > 0)

            write(fileno(stdout), buf, nrcvd);

exit(0);

}

/* Accept an incoming connection request.

* The argument passed to us in the form:

*

* PORT.HOST

*/

int Accept_Conn(char* cp)

{

        struct sockaddr_in sin;

        memset (&sin, 0, sizeof(sin));

        /*

        * Set up the sock_addr_in structure based on the

        * argument.

        */

        sin.sin_port = atoi (cp);

        cp = strchr (cp, '.') + 1;

        if ((sin.sin_addr.s_addr = inet_addr (cp)) == 0) {

                printf ("Bad value for %s\n", cp);

}

sin.sin_family = AF_INET;

/*

* Create a socket so that we can use it for

* accepting the connection.

*/

if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0) {

        perror ("socket");

        return 0;

}

        /*

        * This is a waited socket, but we use the trick of

        * nowait accept_nw2, because this does just what we

        * need (accept a connection as a new socket).

        */

        if (accept_nw2(sock, (struct sockaddr*)&sin, 01) < 0) {

                perror ("accept_nw2");

                return 0;

        }

        return 1;

}

4.complie command

?tacl macro

== RUN udpcc prog

$system.system.c/in %1%,out $s.#cc/ %1%o;symbols,wide,list,&

 runnable,saveabend,&

 ssv0 "$dev.raytcp",&

 ssv1 "$system.system",&

 ssv2 "$system.ztcpip",&

 ssv3 "$system.zspidef",&

 ssv4 "$system.zsysdefs",&

 search "$system.ztcpip.libinetw" %2 to *%

5.complie method

run cc svrln2 ,它會產生 svrln2o 的object code

6.不用去 run svrln2o object, 因為 Nonstop Server 的 LISTNER 會LISTEN port 15002

   然後去 execute svrln2o 這隻object