2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"); you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied. See the License for the
16 specific language governing permissions and limitations
32 proto : Thrift.Protocol.t;
33 calc : Calculator.client ;
36 let connect ~host port =
37 let tx = new TSocket.t host port in
38 let proto = new TBinaryProtocol.t tx in
39 let calc = new Calculator.client proto proto in
41 { trans = tx ; proto = proto; calc = calc }
45 let cli = connect ~host:"127.0.0.1" 9090 in
48 Printf.printf "ping()\n" ; flush stdout ;
49 (let sum = cli.calc#add (Int32.of_int 1) (Int32.of_int 1) in
50 Printf.printf "1+1=%ld\n" sum ;
53 w#set_op Operation.DIVIDE ;
54 w#set_num1 (Int32.of_int 1) ;
55 w#set_num2 (Int32.of_int 0) ;
57 let quotient = cli.calc#calculate (Int32.of_int 1) w in
58 Printf.printf "Whoa? We can divide by zero!\n" ; flush stdout
59 with InvalidOperation io ->
60 Printf.printf "InvalidOperation: %s\n" io#grab_why ; flush stdout) ;
62 w#set_op Operation.SUBTRACT ;
63 w#set_num1 (Int32.of_int 15) ;
64 w#set_num2 (Int32.of_int 10) ;
65 let diff = cli.calc#calculate (Int32.of_int 1) w in
66 Printf.printf "15-10=%ld\n" diff ; flush stdout) ;
67 (let ss = cli.calc#getStruct (Int32.of_int 1) in
68 Printf.printf "Check log: %s\n" ss#grab_value ; flush stdout) ;
70 with Transport.E (_,what) ->
71 Printf.printf "ERROR: %s\n" what ; flush stdout