blob: e0b47b6357b66a3ae45e00d2285f693e600e1f0a [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
10transport = TSocket.new('localhost', 9090)
11protocol = TBinaryProtocol.new(transport)
12client = Calculator::Client.new(protocol)
13
14transport.open()
15
16client.ping()
17print "ping()\n"
18
19sum = client.add(1,1)
20print "1+1=", sum, "\n"
21
22work = Work.new()
23
24begin
25 work.op = Operation::DIVIDE
26 work.num1 = 1
27 work.num2 = 0
28 quot = client.calculate(1, work)
29 puts "Whoa, we can divide by 0 now?"
30rescue InvalidOperation => io
31 print "InvalidOperation: ", io.why, "\n"
32end
33
34work.op = Operation::SUBTRACT
35work.num1 = 15
36work.num2 = 10
37diff = client.calculate(1, work)
38print "15-10=", diff, "\n"
39
40log = client.getStruct(1)
41print "Log: ", log.value, "\n"
42
43transport.close()