blob: f4ff7b3ef12d20bc893ee0ac04760fd93a77d0fb [file] [log] [blame]
Christopher Piro8ba81572008-01-15 12:04:15 +00001-module(client).
2
3-include("thrift.hrl").
4-include("transport/tSocket.hrl").
5-include("protocol/tBinaryProtocol.hrl").
6
7-include("calculator_thrift.hrl").
8
9-export([t/0]).
10
11t() ->
12 Host = "dev020",
13 Port = 9999,
14
15 _Sock = oop:start_new(tSocket, [Host, Port]),
16 Trans = oop:start_new(tBufferedTransport, [_Sock]),
17 Prot = oop:start_new(tBinaryProtocol, [Trans]),
18
19 ?R0(Trans, effectful_open),
20
21 Client = calculator_thrift:new(Prot),
22
23 calculator_thrift:ping(Client),
24 p("ping"),
25
26 %%
27 %% sum = client.add(1,1)
28 %% print "1+1=", sum, "\n"
29 %%
30 %% sum = client.add(1,4)
31 %% print "1+4=", sum, "\n"
32 %%
33 %% work = Work.new()
34 %%
35 %% work.op = Operation::SUBTRACT
36 %% work.num1 = 15
37 %% work.num2 = 10
38 %% diff = client.calculate(1, work)
39 %% print "15-10=", diff, "\n"
40 %%
41 %% log = client.getStruct(1)
42 %% print "Log: ", log.value, "\n"
43 %%
44 %% begin
45 %% work.op = Operation::DIVIDE
46 %% work.num1 = 1
47 %% work.num2 = 0
48 %% quot = client.calculate(1, work)
49 %% puts "Whoa, we can divide by 0 now?"
50 %% rescue InvalidOperation => io
51 %% print "InvalidOperation: ", io.why, "\n"
52 %% end
53 %%
54 %% client.zip()
55 %% print "zip\n"
56 %%
57 %% transport.close()
58 %%
59 %% rescue TException => tx
60 %% print 'TException: ', tx.message, "\n"
61 %% end
62 %%
63 %%
64 %%
65 %% XXX if we don't close, the connection doesn't time out on the other side
66 ?R0(Trans, effectful_close),
67
68 ok.