blob: bcf130094073ea8ecd2f86e6207df15968772bd0 [file] [log] [blame]
Mark Slee07a3aab2007-03-07 05:45:10 +00001#!/usr/bin/env ruby
2
3$:.push('../gen-rb')
4
5require 'thrift/transport/tsocket'
6require 'thrift/protocol/tbinaryprotocol'
7
8require 'Calculator'
9
Mark Slee07a3aab2007-03-07 05:45:10 +000010begin
Mark Slee76791962007-03-14 02:47:35 +000011
12 transport = TBufferedTransport.new(TSocket.new('localhost', 9090))
13 protocol = TBinaryProtocol.new(transport)
14 client = Calculator::Client.new(protocol)
15
16 transport.open()
17
18 client.ping()
19 print "ping()\n"
20
21 sum = client.add(1,1)
22 print "1+1=", sum, "\n"
23
24 work = Work.new()
25
26 begin
27 work.op = Operation::DIVIDE
28 work.num1 = 1
29 work.num2 = 0
30 quot = client.calculate(1, work)
31 puts "Whoa, we can divide by 0 now?"
32 rescue InvalidOperation => io
33 print "InvalidOperation: ", io.why, "\n"
34 end
35
36 work.op = Operation::SUBTRACT
37 work.num1 = 15
38 work.num2 = 10
39 diff = client.calculate(1, work)
40 print "15-10=", diff, "\n"
41
42 log = client.getStruct(1)
43 print "Log: ", log.value, "\n"
44
45 transport.close()
46
47rescue TException => tx
48 print 'TException: ', tx.message, "\n"
Mark Slee07a3aab2007-03-07 05:45:10 +000049end