MCPcopy Create free account
hub / github.com/apache/thrift / main

Function main

tutorial/cpp/CppClient.cpp:36–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34using namespace shared;
35
36int main() {
37 std::shared_ptr<TTransport> socket(new TSocket("localhost", 9090));
38 std::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
39 std::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
40 CalculatorClient client(protocol);
41
42 try {
43 transport->open();
44
45 client.ping();
46 cout << "ping()" << '\n';
47
48 cout << "1 + 1 = " << client.add(1, 1) << '\n';
49
50 Work work;
51 work.op = Operation::DIVIDE;
52 work.num1 = 1;
53 work.num2 = 0;
54
55 try {
56 client.calculate(1, work);
57 cout << "Whoa? We can divide by zero!" << '\n';
58 } catch (InvalidOperation& io) {
59 cout << "InvalidOperation: " << io.why << '\n';
60 // or using generated operator<<: cout << io << '\n';
61 // or by using std::exception native method what(): cout << io.what() << '\n';
62 }
63
64 work.op = Operation::SUBTRACT;
65 work.num1 = 15;
66 work.num2 = 10;
67 int32_t diff = client.calculate(1, work);
68 cout << "15 - 10 = " << diff << '\n';
69
70 // Note that C++ uses return by reference for complex types to avoid
71 // costly copy construction
72 SharedStruct ss;
73 client.getStruct(ss, 1);
74 cout << "Received log: " << ss << '\n';
75
76 transport->close();
77 } catch (TException& tx) {
78 cout << "ERROR: " << tx.what() << '\n';
79 }
80}

Callers

nothing calls this directly

Calls 7

closeMethod · 0.65
openMethod · 0.45
pingMethod · 0.45
addMethod · 0.45
calculateMethod · 0.45
getStructMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected