00010 rem BujuClientBBx: Buju Client
00020 rem ********************************************************************
00030 rem You must have an SSL network device defined in your BBx config file.
00040 rem e.g., N0 SSL "Buju Java Server" NODELAY
00050 rem ********************************************************************
00100 test:
00110   rem Test
00120   if tcb(13)=0 call pgm(-2); escape; rem endif
00150   gosub test_run_
00160   exit
00200 init_args:
00210   rem Initializes argument string template.
00220   rem @return arg$: argument string template
00230   setesc esc_handler_; seterr err_handler_
00240   enter arg$
00250   gosub init_args_
00260   exit
01000 open_connection:
01010   setesc esc_handler_; seterr err_handler_
01020   enter arg$
01030   u = unt; open (u,mode="host="+arg.sockhost$+",port="+str(arg.sockport))arg.sockdev$
01035   arg.sockunt = u
01040   result$ = fneval$(arg.login$), arg.connected = 1
01045   exit
01050 close_connection:
01060   setesc esc_handler_; seterr err_handler_
01070   enter arg$,result$
01080   gosub check_connection_
01085   u = arg.sockunt, result$ = fneval$(".close()"), arg.sockunt = 0, arg.connected = 0
01090   close(u)
01095   exit
01100 eval_source:
01110   setesc esc_handler_; seterr err_handler_
01120   enter arg$,source$,result$
01130   gosub check_connection_
01140   u = arg.sockunt, result$=fneval$(source$,err=eval_source_err_)
01150   exit
01170   eval_source_err_:
01180     exit err
07000 check_connection_:
07020   if arg.connected = 0 exit 14; rem endif
07090   return
07200 init_args_:
07210   rem @return arg$: initialized
07220   dim arg$:" connected:u(1), sockport:u(2), sockunt:u(2), sockdev:c(2*), sockhost:c(1*), login:c(1*)"
07260   arg.sockdev$ = "N0"
07270   arg.sockhost$ = "localhost"
07280   arg.sockport = 2183
07290   return
08000 rem Functions
08060 def fneval$(source$)
08062   result$ = "", source$ = cvs(source$,3)
08064   if source$ = "" return result$; rem endif
08066   source$ = bin(len(source$), 4) + source$
08068   write record(arg.sockunt)source$
08070   dim x$:"len:i(4)"; read record(arg.sockunt,siz=4,tim=30)x$
08072   if x.len <> 0 read record(arg.sockunt,siz=abs(x.len),tim=5)result$; rem endif
08074   if x.len < 0 fnerr 20; rem endif
08076   return result$
08078   fnend
08700 err_handler_:
08800 esc_handler_:
08810   exit err
10000 test_run_:
10010   setesc test_esc_handler_; seterr test_err_handler_
10020   print 'cs',"Buju Client: BBx"
10040   call pgm(-2)+"::init_args",arg$
10050   xfield = 0, field_count = 3, hostf = 1, portf = 2, loginf = 3
10060   dim xfield[field_count - 1]
10070   xfield[0] = hostf, xfield[1] = portf, xfield[2] = loginf; rem Order of input
10100   while xfield >= 0 and xfield < field_count
10110     switch xfield[xfield]
10200       case hostf
10210         rem Host
10220         input "Host (e.g.: localhost): ",x$
10230         if x$ = "" xfield = xfield - 1; break; rem endif
10240         arg.sockhost$ = x$
10250         xfield = xfield + 1
10260         break
10300       case portf
10310         rem Port
10320         portf_inp: input "Port (e.g.: 2183): ",x$
10330         if x$="" xfield = xfield - 1; break; rem endif
10340         arg.sockport = int(abs(num(x$,err=portf_inp)))
10350         xfield = xfield + 1
10360         break
10400       case loginf
10410         rem Login arguments
10420         input "Login arguments (e.g.: user=user passwd=user123):",'lf',x$
10430         if x$="" xfield = xfield - 1; break; rem endif
10440         arg.login$ = x$
10450         xfield = xfield + 1
10460         break
10500       case default
10510         xfield = -1
10520         break
10980     swend
10990   wend
10995   if xfield = -1 return; rem endif
11100   rem Open connection to the server
11110   print 'lf',"Opening connection..."
11120   call pgm(-2) + "::open_connection",arg$
11150   print "Test client ready.",'lf',"At prompt, enter Java code to evaluate.",'lf',"Enter 'quit' to exit."
11900   interactive_test_:
11910     rem Interactive send/receive
11920     running = 1
11930     while running
11940       input "Send: ",x$
11950       if x$="quit" running = 0; continue; rem endif
11960       print fneval$(x$,err=interactive_test_err_)
11970       continue
11980       interactive_test_err_:
11990         print "Error ",err," ",result$
11995         continue
12000     wend
14950   rem Close connection to the server
14960   print 'lf',"Closing connection..."
14970   call pgm(-2) + "::close_connection",arg$,result$
14980   print result$
14990   return
15700 test_err_handler_:
15710 test_esc_handler_:
15720   if arg.sockunt close(arg.sockunt); rem endif
15790   exit err
