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 moduleclient;
20 21 importstd.stdio;
22 importthrift.base;
23 importthrift.codegen.client;
24 importthrift.protocol.binary;
25 importthrift.transport.buffered;
26 importthrift.transport.socket;
27 28 importtutorial.Calculator;
29 importtutorial.tutorial_types;
30 31 voidmain() {
32 autosocket = newTSocket("localhost", 9090);
33 autotransport = newTBufferedTransport(socket);
34 autoprotocol = tBinaryProtocol(transport);
35 autoclient = tClient!Calculator(protocol);
36 37 transport.open();
38 39 client.ping();
40 writeln("ping()");
41 42 intsum = client.add(1, 1);
43 writefln("1 + 1 = %s", sum);
44 45 autowork = Work();
46 work.op = Operation.DIVIDE;
47 work.num1 = 1;
48 work.num2 = 0;
49 try {
50 intquotient = client.calculate(1, work);
51 writeln("Whoa we can divide by 0");
52 } catch (InvalidOperationio) {
53 writeln("Invalid operation: " ~ io.why);
54 }
55 56 work.op = Operation.SUBTRACT;
57 work.num1 = 15;
58 work.num2 = 10;
59 intdiff = client.calculate(1, work);
60 writefln("15 - 10 = %s", diff);
61 62 autolog = client.getStruct(1);
63 writefln("Check log: %s", log.value);
64 }