mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 02:45:22 +00:00
3f1d8c7cf6
Summary: Added examples for all examples except inheritance and application exception handling (divide by zero); looks like both are currently broken. Weak. Reviewed By: eletuchy Test Plan: works just like RubyClient.rb (modulo the commented out bits) Revert Plan: ok git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665428 13f79535-47bb-0310-9956-ffa450edef68
74 lines
1.8 KiB
Erlang
74 lines
1.8 KiB
Erlang
-module(client).
|
|
|
|
-include("thrift.hrl").
|
|
-include("transport/tSocket.hrl").
|
|
-include("protocol/tBinaryProtocol.hrl").
|
|
|
|
-include("calculator_thrift.hrl").
|
|
|
|
-export([go/0]).
|
|
|
|
p(X) ->
|
|
io:format("~p~n", [X]),
|
|
ok.
|
|
|
|
t() ->
|
|
thrift:start(),
|
|
Host = "dev020",
|
|
Port = 9999,
|
|
|
|
try
|
|
_Sock = oop:start_new(tSocket, [Host, Port]),
|
|
Trans = oop:start_new(tBufferedTransport, [_Sock]),
|
|
Prot = oop:start_new(tBinaryProtocol, [Trans]),
|
|
|
|
?R0(Trans, effectful_open),
|
|
|
|
Client = calculator_thrift:new(Prot),
|
|
|
|
calculator_thrift:ping(Client),
|
|
io:format("ping~n", []),
|
|
|
|
Sum = calculator_thrift:add(Client, 1, 1),
|
|
io:format("1+1=~p~n", [Sum]),
|
|
|
|
Sum1 = calculator_thrift:add(Client, 1, 4),
|
|
io:format("1+4=~p~n", [Sum1]),
|
|
|
|
Work = #work{op=?tutorial_SUBTRACT,
|
|
num1=15,
|
|
num2=10},
|
|
Diff = calculator_thrift:calculate(Client, 1, Work),
|
|
io:format("15-10=~p~n", [Diff]),
|
|
|
|
%% xxx inheritance doesn't work
|
|
%% Log = sharedService_thrift:getStruct(Client, 1),
|
|
%% io:format("Log: ~p~n", [Log]),
|
|
|
|
%% xxx neither do exceptions :(
|
|
try
|
|
Work1 = #work{op=?tutorial_DIVIDE,
|
|
num1=1,
|
|
num2=0},
|
|
_Quot = (calculator_thrift:calculate(Client, 1, Work1)),
|
|
|
|
io:format("LAME: exception handling is broken~n", [])
|
|
catch
|
|
Z ->
|
|
p(Z)
|
|
%% rescue InvalidOperation => io
|
|
%% print "InvalidOperation: ", io.why, "\n"
|
|
%% end
|
|
end,
|
|
|
|
calculator_thrift:zip(Client),
|
|
io:format("zip~n", []),
|
|
|
|
?R0(Trans, effectful_close)
|
|
|
|
catch
|
|
Y ->
|
|
p(Y)
|
|
end,
|
|
ok.
|