[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.5

1.1       ohara       1: /* -*- mode: C -*- */
1.5     ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/zclient.c,v 1.4 2003/01/13 12:03:13 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) {
1.4       ohara      31:             ox_printf("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:
1.5     ! ohara      43:     ox_stderr_init(stderr);
1.2       ohara      44:        if (argc < 3) {
1.4       ohara      45:         ox_printf("we have a few argument.\n");
                     46:         ox_printf("Usage:\n  %s [remotehost] [command]\n", argv[0]);
1.2       ohara      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.4       ohara      54:         ox_printf("zclient:: I cannot open a server.\n");
1.1       ohara      55:         exit(1);
                     56:     }
1.4       ohara      57:     ox_printf("zclient:: I succeed to open an OX server.\n");
1.2       ohara      58:
                     59:        if(oxf_execute_cmd(oxfp, cmd) != NULL) {
1.4       ohara      60:         ox_printf("zclient:: I succeed to connect a calc server!!\n");
1.2       ohara      61:        }
                     62:
1.4       ohara      63:     oxf_close(oxfp);
                     64:     ox_printf("zclient:: closed.\n");
1.1       ohara      65:     return 0;
                     66: }

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