Annotation of OpenXM/src/ox_toolkit/zclient.c, Revision 1.3
1.1 ohara 1: /* -*- mode: C -*- */
1.3 ! ohara 2: /* $OpenXM: OpenXM/src/ox_toolkit/zclient.c,v 1.2 2000/10/12 15:30:32 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.3 ! ohara 31: fprintf(ox_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:
1.3 ! ohara 43: ox_stderr_init(NULL);
! 44: setbuf(ox_stderr, NULL);
1.2 ohara 45: if (argc < 3) {
1.3 ! ohara 46: fprintf(ox_stderr, "we have a few argument.\n");
! 47: fprintf(ox_stderr, "Usage:\n %s [remotehost] [command]\n", argv[0]);
1.2 ohara 48: return 0;
49: }
1.1 ohara 50:
1.2 ohara 51: remote = argv[1];
52: cmd = argv[2];
1.1 ohara 53:
1.2 ohara 54: if ((oxfp = open_server(remote)) == NULL) {
1.3 ! ohara 55: fprintf(ox_stderr, "zclient:: I cannot open a server.\n");
1.1 ohara 56: exit(1);
57: }
1.3 ! ohara 58: fprintf(ox_stderr, "zclient:: I succeed to open an OX server.\n");
1.2 ohara 59:
60: if(oxf_execute_cmd(oxfp, cmd) != NULL) {
1.3 ! ohara 61: fprintf(ox_stderr, "zclient:: I succeed to connect a calc server!!\n");
1.2 ohara 62: }
63:
64: oxf_close(oxfp);
1.3 ! ohara 65: fprintf(ox_stderr, "zclient:: closed.\n");
1.1 ohara 66: return 0;
67: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>