diff options
author | Christopher Piro <cpiro@apache.org> | 2008-01-15 12:04:15 +0000 |
---|---|---|
committer | Christopher Piro <cpiro@apache.org> | 2008-01-15 12:04:15 +0000 |
commit | 8ba81573b3e82103b0ecc7af14d253ebe2489260 (patch) | |
tree | 4f9499d4a2061c0862c386f2b515e3bc05c41d77 /tutorial/erl | |
parent | 5165f3e65ed5a072099f561d28b3b3994ab8aa95 (diff) | |
download | thrift-8ba81573b3e82103b0ecc7af14d253ebe2489260.tar.gz |
[thrift] preliminary tthrift tutorial client for Erlang
Summary: we haven't had a client tutorial for the longest time -- added one that basically works. will iron the bugs out in due order.
Reviewed By: eletuchy
Test Plan: works when launched like server.sh
Revert Plan: ok
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665427 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'tutorial/erl')
-rw-r--r-- | tutorial/erl/client.erl | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tutorial/erl/client.erl b/tutorial/erl/client.erl new file mode 100644 index 000000000..f4ff7b3ef --- /dev/null +++ b/tutorial/erl/client.erl @@ -0,0 +1,68 @@ +-module(client). + +-include("thrift.hrl"). +-include("transport/tSocket.hrl"). +-include("protocol/tBinaryProtocol.hrl"). + +-include("calculator_thrift.hrl"). + +-export([t/0]). + +t() -> + Host = "dev020", + Port = 9999, + + _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), + p("ping"), + + %% + %% sum = client.add(1,1) + %% print "1+1=", sum, "\n" + %% + %% sum = client.add(1,4) + %% print "1+4=", sum, "\n" + %% + %% work = Work.new() + %% + %% work.op = Operation::SUBTRACT + %% work.num1 = 15 + %% work.num2 = 10 + %% diff = client.calculate(1, work) + %% print "15-10=", diff, "\n" + %% + %% log = client.getStruct(1) + %% print "Log: ", log.value, "\n" + %% + %% begin + %% work.op = Operation::DIVIDE + %% work.num1 = 1 + %% work.num2 = 0 + %% quot = client.calculate(1, work) + %% puts "Whoa, we can divide by 0 now?" + %% rescue InvalidOperation => io + %% print "InvalidOperation: ", io.why, "\n" + %% end + %% + %% client.zip() + %% print "zip\n" + %% + %% transport.close() + %% + %% rescue TException => tx + %% print 'TException: ', tx.message, "\n" + %% end + %% + %% + %% + %% XXX if we don't close, the connection doesn't time out on the other side + ?R0(Trans, effectful_close), + + ok. |