David Reiss | 8a162a5 | 2008-06-11 01:03:16 +0000 | [diff] [blame] | 1 | -module(client). |
| 2 | |
| 3 | -include("calculator_thrift.hrl"). |
| 4 | |
| 5 | -export([t/0]). |
| 6 | |
| 7 | p(X) -> |
| 8 | io:format("~p~n", [X]), |
| 9 | ok. |
| 10 | |
| 11 | t() -> |
| 12 | Port = 9999, |
| 13 | |
| 14 | {ok, Client} = thrift_client:start_link("127.0.0.1", |
| 15 | Port, |
| 16 | calculator_thrift), |
| 17 | |
| 18 | thrift_client:call(Client, ping, []), |
| 19 | io:format("ping~n", []), |
| 20 | |
| 21 | {ok, Sum} = thrift_client:call(Client, add, [1, 1]), |
| 22 | io:format("1+1=~p~n", [Sum]), |
| 23 | |
| 24 | {ok, Sum1} = thrift_client:call(Client, add, [1, 4]), |
| 25 | io:format("1+4=~p~n", [Sum1]), |
| 26 | |
| 27 | Work = #work{op=?tutorial_SUBTRACT, |
| 28 | num1=15, |
| 29 | num2=10}, |
| 30 | {ok, Diff} = thrift_client:call(Client, calculate, [1, Work]), |
| 31 | io:format("15-10=~p~n", [Diff]), |
| 32 | |
| 33 | {ok, Log} = thrift_client:call(Client, getStruct, [1]), |
| 34 | io:format("Log: ~p~n", [Log]), |
| 35 | |
| 36 | try |
| 37 | Work1 = #work{op=?tutorial_DIVIDE, |
| 38 | num1=1, |
| 39 | num2=0}, |
| 40 | {ok, _Quot} = thrift_client:call(Client, calculate, [2, Work1]), |
| 41 | |
| 42 | io:format("LAME: exception handling is broken~n", []) |
| 43 | catch |
| 44 | Z -> |
| 45 | io:format("Got exception where expecting - the " ++ |
| 46 | "following is NOT a problem!!!~n"), |
| 47 | p(Z) |
| 48 | end, |
| 49 | |
| 50 | |
| 51 | {ok, ok} = thrift_client:call(Client, zip, []), |
| 52 | io:format("zip~n", []), |
| 53 | |
| 54 | ok = thrift_client:close(Client), |
| 55 | ok. |