5 #include <protocol/TBinaryProtocol.h>
6 #include <transport/TSocket.h>
7 #include <transport/TTransportUtils.h>
9 #include "../gen-cpp/Calculator.h"
12 using namespace facebook::thrift
;
13 using namespace facebook::thrift::protocol
;
14 using namespace facebook::thrift::transport
;
16 using namespace tutorial
;
17 using namespace shared
;
19 using namespace boost
;
21 int main(int argc
, char** argv
) {
22 shared_ptr
<TTransport
> socket(new TSocket("localhost", 9090));
23 shared_ptr
<TTransport
> transport(new TBufferedTransport(socket
));
24 shared_ptr
<TProtocol
> protocol(new TBinaryProtocol(transport
));
25 CalculatorClient
client(protocol
);
33 int32_t sum
= client
.add(1,1);
34 printf("1+1=%d\n", sum
);
42 int32_t quotient
= client
.calculate(1, work
);
43 printf("Whoa? We can divide by zero!\n");
44 } catch (InvalidOperation
&io
) {
45 printf("InvalidOperation: %s\n", io
.why
.c_str());
51 int32_t diff
= client
.calculate(1, work
);
52 printf("15-10=%d\n", diff
);
54 // Note that C++ uses return by reference for complex types to avoid
55 // costly copy construction
57 client
.getStruct(ss
, 1);
58 printf("Check log: %s\n", ss
.value
.c_str());
61 } catch (TException
&tx
) {
62 printf("ERROR: %s\n", tx
.what());