1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
(* $Id$ *)
(* A client for all sample servers in this directory *)
open Printf
let start() =
let host = ref "localhost" in
let port = ref None in
let query = ref None in
let tmo = ref (-1.0) in
Arg.parse
[ "-host", Arg.Set_string host,
"<hostname> Contact the server on this host (default: localhost)";
"-port", Arg.Int (fun n -> port := Some n),
"<port> Contact the server at this port";
"-timeout", Arg.Set_float tmo,
"<tmo> Set a timeout value in seconds";
]
(fun s -> query := Some s)
"usage: test_client [options] <query>";
let query_string =
match !query with
| None ->
failwith "Query is missing on the command-line";
| Some q ->
q in
try
let rpc_client =
match !port with
| None ->
failwith "Port is missing on the command-line"
| Some p ->
Operation_clnt.P.V.create_client
(Rpc_client.Inet(!host,p)) Rpc.Tcp
in
Rpc_client.configure rpc_client 0 !tmo;
let r = Operation_clnt.P.V.operation rpc_client query_string in
printf "Result: %s\n%!" r;
Rpc_client.shut_down rpc_client;
with
| e ->
printf "Exception: %s\n%!" (Netexn.to_string e)
let () =
Netsys_signal.init();
start()
|