1 /*
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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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
17 * under the License.
18 */
19 module client;
20
21 import std.stdio;
22 import thrift.base;
23 import thrift.codegen.client;
24 import thrift.protocol.binary;
25 import thrift.transport.buffered;
26 import thrift.transport.socket;
27
28 import tutorial.Calculator;
29 import tutorial.tutorial_types;
30
main()31 void main() {
32 auto socket = new TSocket("localhost", 9090);
33 auto transport = new TBufferedTransport(socket);
34 auto protocol = tBinaryProtocol(transport);
35 auto client = tClient!Calculator(protocol);
36
37 transport.open();
38
39 client.ping();
40 writeln("ping()");
41
42 int sum = client.add(1, 1);
43 writefln("1 + 1 = %s", sum);
44
45 auto work = Work();
46 work.op = Operation.DIVIDE;
47 work.num1 = 1;
48 work.num2 = 0;
49 try {
50 int quotient = client.calculate(1, work);
51 writeln("Whoa we can divide by 0");
52 } catch (InvalidOperation io) {
53 writeln("Invalid operation: " ~ io.why);
54 }
55
56 work.op = Operation.SUBTRACT;
57 work.num1 = 15;
58 work.num2 = 10;
59 int diff = client.calculate(1, work);
60 writefln("15 - 10 = %s", diff);
61
62 auto log = client.getStruct(1);
63 writefln("Check log: %s", log.value);
64 }
65