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 | |
Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 10 | begin |
Mark Slee | 7679196 | 2007-03-14 02:47:35 +0000 | [diff] [blame] | 11 | |
| 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 | |
| 47 | rescue TException => tx |
| 48 | print 'TException: ', tx.message, "\n" |
Mark Slee | 07a3aab | 2007-03-07 05:45:10 +0000 | [diff] [blame] | 49 | end |