Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 1 | #!/usr/bin/env ruby |
| 2 | |
| 3 | $:.push('../gen-rb') |
| 4 | |
| 5 | require 'thrift/transport/tsocket' |
| 6 | require 'thrift/protocol/tbinaryprotocol' |
| 7 | |
| 8 | require 'Calculator' |
| 9 | |
| 10 | transport = TSocket.new('localhost', 9090) |
| 11 | protocol = TBinaryProtocol.new(transport) |
| 12 | client = Calculator::Client.new(protocol) |
| 13 | |
| 14 | transport.open() |
| 15 | |
| 16 | client.ping() |
| 17 | print "ping()\n" |
| 18 | |
| 19 | sum = client.add(1,1) |
| 20 | print "1+1=", sum, "\n" |
| 21 | |
| 22 | work = Work.new() |
| 23 | |
| 24 | begin |
| 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?" |
| 30 | rescue InvalidOperation => io |
| 31 | print "InvalidOperation: ", io.why, "\n" |
| 32 | end |
| 33 | |
| 34 | work.op = Operation::SUBTRACT |
| 35 | work.num1 = 15 |
| 36 | work.num2 = 10 |
| 37 | diff = client.calculate(1, work) |
| 38 | print "15-10=", diff, "\n" |
| 39 | |
| 40 | log = client.getStruct(1) |
| 41 | print "Log: ", log.value, "\n" |
| 42 | |
| 43 | transport.close() |