[BACK]Return to zclient.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_toolkit

Annotation of OpenXM/src/ox_toolkit/zclient.c, Revision 1.2

1.1       ohara       1: /* -*- mode: C -*- */
1.2     ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/zclient.c,v 1.1 2000/10/10 06:51:41 ohara Exp $ */
1.1       ohara       3:
                      4: /* A sample implementation of an OpenXM client with OpenXM C library */
                      5:
                      6: #include <stdio.h>
                      7: #include <stdlib.h>
                      8: #include <unistd.h>
                      9: #include <string.h>
                     10: #include "ox_toolkit.h"
                     11:
1.2     ! ohara      12: static OXFILE *connection(int listened, char *passwd)
1.1       ohara      13: {
                     14:     OXFILE *oxfp = oxf_connect_passive(listened);
                     15:     if(oxf_confirm_client(oxfp, passwd)) {
                     16:         oxf_determine_byteorder_client(oxfp);
                     17:         return oxfp;
                     18:     }
                     19:     oxf_close(oxfp);
                     20:     return NULL;
                     21: }
                     22:
                     23: OXFILE *open_server(char *remote_host)
                     24: {
                     25:     short port;
                     26:     int listen;
                     27:     char *passwd = generate_otp();
                     28:
1.2     ! ohara      29:     if ((listen = oxf_listen(&port)) != -1) {
1.1       ohara      30:         if (oxc_start(remote_host, port, passwd) != 0) {
                     31:             fprintf(stderr, "zclient:: remotehost = %s.\n", remote_host);
1.2     ! ohara      32:             return connection(listen, passwd);
1.1       ohara      33:         }
                     34:     }
                     35:     return NULL;
                     36: }
                     37:
                     38: int main(int argc, char* argv[])
                     39: {
1.2     ! ohara      40:     OXFILE *oxfp;
        !            41:        char *remote, *cmd;
1.1       ohara      42:
                     43:     setbuf(stderr, NULL);
1.2     ! ohara      44:        if (argc < 3) {
        !            45:                fprintf(stderr, "we have a few argument.\n");
        !            46:                fprintf(stderr, "Usage:\n  %s [remotehost] [command]\n", argv[0]);
        !            47:                return 0;
        !            48:        }
1.1       ohara      49:
1.2     ! ohara      50:        remote = argv[1];
        !            51:        cmd    = argv[2];
1.1       ohara      52:
1.2     ! ohara      53:     if ((oxfp = open_server(remote)) == NULL) {
1.1       ohara      54:         fprintf(stderr, "zclient:: I cannot open a server.\n");
                     55:         exit(1);
                     56:     }
1.2     ! ohara      57:     fprintf(stderr, "zclient:: I succeed to open an OX server.\n");
        !            58:
        !            59:        if(oxf_execute_cmd(oxfp, cmd) != NULL) {
        !            60:                fprintf(stderr, "zclient:: I succeed to connect a calc server!!\n");
        !            61:        }
        !            62:
        !            63:        oxf_close(oxfp);
        !            64:     fprintf(stderr, "zclient:: closed.\n");
1.1       ohara      65:     return 0;
                     66: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>