2007-03-07 05:45:10 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
$:.push('../gen-rb')
|
|
|
|
|
2007-07-25 22:41:00 +00:00
|
|
|
require 'thrift/transport/tsocket.rb'
|
|
|
|
require 'thrift/protocol/tbinaryprotocol.rb'
|
2007-03-07 05:45:10 +00:00
|
|
|
|
|
|
|
require 'Calculator'
|
|
|
|
|
|
|
|
begin
|
2007-07-25 22:41:00 +00:00
|
|
|
port = ARGV[0] || 9090
|
2007-03-14 02:47:35 +00:00
|
|
|
|
2007-07-25 22:41:00 +00:00
|
|
|
transport = TBufferedTransport.new(TSocket.new('localhost', port))
|
2007-03-14 02:47:35 +00:00
|
|
|
protocol = TBinaryProtocol.new(transport)
|
|
|
|
client = Calculator::Client.new(protocol)
|
2007-07-25 22:41:00 +00:00
|
|
|
|
2007-03-14 02:47:35 +00:00
|
|
|
transport.open()
|
2007-07-25 22:41:00 +00:00
|
|
|
|
2007-03-14 02:47:35 +00:00
|
|
|
client.ping()
|
|
|
|
print "ping()\n"
|
2007-07-25 22:41:00 +00:00
|
|
|
|
2007-03-14 02:47:35 +00:00
|
|
|
sum = client.add(1,1)
|
|
|
|
print "1+1=", sum, "\n"
|
2007-07-25 22:41:00 +00:00
|
|
|
|
|
|
|
sum = client.add(1,4)
|
|
|
|
print "1+4=", sum, "\n"
|
|
|
|
|
2007-03-14 02:47:35 +00:00
|
|
|
work = Work.new()
|
2007-07-25 22:41:00 +00:00
|
|
|
|
|
|
|
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"
|
|
|
|
|
2007-03-14 02:47:35 +00:00
|
|
|
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
|
2007-07-25 22:41:00 +00:00
|
|
|
|
|
|
|
client.zip()
|
|
|
|
print "zip\n"
|
|
|
|
|
2007-03-14 02:47:35 +00:00
|
|
|
transport.close()
|
|
|
|
|
|
|
|
rescue TException => tx
|
|
|
|
print 'TException: ', tx.message, "\n"
|
2007-03-07 05:45:10 +00:00
|
|
|
end
|