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

File: [local] / OpenXM / src / ox_toolkit / zclient.c (download)

Revision 1.6, Mon Sep 15 09:31:42 2003 UTC (20 years, 7 months ago) by ohara
Branch: MAIN
CVS Tags: new-mathcap-branch, R_1_3_1-2, RELEASE_1_3_1_13b, RELEASE_1_2_3_12, RELEASE_1_2_3, RELEASE_1_2_2_KNOPPIX_b, RELEASE_1_2_2_KNOPPIX, KNOPPIX_2006, HEAD, DEB_REL_1_2_3-9
Changes since 1.5: +4 -2 lines

Add some "cast".
Fixed some bugs.

/* -*- mode: C -*- */
/* $OpenXM: OpenXM/src/ox_toolkit/zclient.c,v 1.6 2003/09/15 09:31:42 ohara Exp $ */

/* A sample implementation of an OpenXM client with OpenXM C library */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "ox_toolkit.h"

int oxc_start(char *remote_host, int port, char *passwd);

static OXFILE *connection(int listened, char *passwd)
{
    OXFILE *oxfp = oxf_connect_passive(listened);
    if(oxf_confirm_client(oxfp, passwd)) {
        oxf_determine_byteorder_client(oxfp);
        return oxfp;
    }
    oxf_close(oxfp);
    return NULL;
}

OXFILE *open_server(char *remote_host)
{
    int port;
    int listen;
    char *passwd = generate_otp();

    if ((listen = oxf_listen(&port)) != -1) {
        if (oxc_start(remote_host, port, passwd) != 0) {
            ox_printf("zclient:: remotehost = %s.\n", remote_host);
            return connection(listen, passwd);
        }
    }
    return NULL;
}

int main(int argc, char* argv[])
{
    OXFILE *oxfp;
	char *remote, *cmd;

    ox_stderr_init(stderr);
	if (argc < 3) {
        ox_printf("we have a few argument.\n");
        ox_printf("Usage:\n  %s [remotehost] [command]\n", argv[0]);
		return 0;
	}

	remote = argv[1];
	cmd    = argv[2];

    if ((oxfp = open_server(remote)) == NULL) {
        ox_printf("zclient:: I cannot open a server.\n");
        exit(1);
    }
    ox_printf("zclient:: I succeed to open an OX server.\n");

	if(oxf_execute_cmd(oxfp, cmd) != NULL) {
        ox_printf("zclient:: I succeed to connect a calc server!!\n");
	}

    oxf_close(oxfp);
    ox_printf("zclient:: closed.\n");
    return 0;
}