=================================================================== RCS file: /home/cvs/OpenXM/src/ox_toolkit/zclient.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -p -r1.1 -r1.2 --- OpenXM/src/ox_toolkit/zclient.c 2000/10/10 06:51:41 1.1 +++ OpenXM/src/ox_toolkit/zclient.c 2000/10/12 15:30:32 1.2 @@ -1,5 +1,5 @@ /* -*- mode: C -*- */ -/* $OpenXM$ */ +/* $OpenXM: OpenXM/src/ox_toolkit/zclient.c,v 1.1 2000/10/10 06:51:41 ohara Exp $ */ /* A sample implementation of an OpenXM client with OpenXM C library */ @@ -7,91 +7,10 @@ #include #include #include -#include -#include -#include - -#include "mysocket.h" #include "ox_toolkit.h" -OXFILE *sv; - -int dumpx(OXFILE *oxfp, int n) +static OXFILE *connection(int listened, char *passwd) { - unsigned char buff[2048]; - int i; - int len = oxf_read(buff, 1, n, oxfp); - - fprintf(stderr, "I have read %d byte from socket.\n", len); - for(i = 0; i < len; i++) { - fprintf(stderr, "%02x ", buff[i]); - if (i%20 == 19) { - fprintf(stderr, "\n"); - } - } - fprintf(stderr, "\n"); - return len; -} - -#define SIZE_CMDLINE 8192 - -static int size = SIZE_CMDLINE; -static char cmdline[SIZE_CMDLINE]; - -static int prompt() -{ - fprintf(stdout, "> "); - fgets(cmdline, size, stdin); - init_parser(cmdline); -} - -#define VERSION 0 -#define ID_STRING "v0.0" - -int test_0() -{ - cmo* c = NULL; -#ifdef DEBUG - fprintf(stderr, "zclient:: calling ox_mathcap().\n"); - c = (cmo *)ox_mathcap(sv); - fprintf(stderr, "zclient:: cmo received.(%p)\n", c); -#else - c = (cmo *)ox_mathcap(sv); -#endif - print_cmo(c); - fflush(stderr); - - mathcap_sysinfo_set(VERSION, ID_STRING, "zclient"); - send_ox_cmo(sv, mathcap_get()); - - ox_reset(sv); - send_ox_cmo(sv, (cmo *)new_cmo_string("N[ArcTan[1]]")); - send_ox_command(sv, SM_executeStringByLocalParser); - send_ox_command(sv, SM_popCMO); - receive_ox_tag(sv); - c = receive_cmo(sv); - fprintf(stderr, "zclient:: cmo received.\n"); - print_cmo(c); -} - -int test_1() -{ - cmo *c, *m; - - mathcap_sysinfo_set(1000, "test!", "zclient"); - m = mathcap_get(); - fprintf(stderr, "zclient:: test cmo_mathcap.\n"); - send_ox_cmo(sv, m); - send_ox_command(sv, SM_popCMO); - receive_ox_tag(sv); - c = receive_cmo(sv); - fprintf(stderr, "zclient:: cmo received.(%p)\n", c); - print_cmo(c); - fputc('\n', stderr); -} - -static OXFILE *mysocketAccept2(int listened, char *passwd) -{ OXFILE *oxfp = oxf_connect_passive(listened); if(oxf_confirm_client(oxfp, passwd)) { oxf_determine_byteorder_client(oxfp); @@ -105,42 +24,43 @@ OXFILE *open_server(char *remote_host) { short port; int listen; - char localhost[MAXHOSTNAMELEN]; char *passwd = generate_otp(); - if (gethostname(localhost, MAXHOSTNAMELEN)==0) { - fprintf(stderr, "zclient:: localhost = %s.\n", localhost); - listen = mysocketListen(localhost, &port); + if ((listen = oxf_listen(&port)) != -1) { if (oxc_start(remote_host, port, passwd) != 0) { fprintf(stderr, "zclient:: remotehost = %s.\n", remote_host); - return mysocketAccept2(listen, passwd); + return connection(listen, passwd); } } return NULL; } -/* Example: - zclient - >(OX_DATA,(CMO_INT32,123)) - >(OX_COMMAND,(SM_popCMO)) - */ - int main(int argc, char* argv[]) { - OXFILE *ctlp; - char *server = "ox_sm1"; + OXFILE *oxfp; + char *remote, *cmd; setbuf(stderr, NULL); + if (argc < 3) { + fprintf(stderr, "we have a few argument.\n"); + fprintf(stderr, "Usage:\n %s [remotehost] [command]\n", argv[0]); + return 0; + } - if (argc>1) { - server = argv[1]; - } + remote = argv[1]; + cmd = argv[2]; - fprintf(stderr, "zclient:: I try to open a server.\n"); - if ((ctlp = open_server("izumi")) == NULL) { + if ((oxfp = open_server(remote)) == NULL) { fprintf(stderr, "zclient:: I cannot open a server.\n"); exit(1); } - fprintf(stderr, "zclient:: I succeed to open a server.\n"); + fprintf(stderr, "zclient:: I succeed to open an OX server.\n"); + + if(oxf_execute_cmd(oxfp, cmd) != NULL) { + fprintf(stderr, "zclient:: I succeed to connect a calc server!!\n"); + } + + oxf_close(oxfp); + fprintf(stderr, "zclient:: closed.\n"); return 0; }