summaryrefslogtreecommitdiff
path: root/tutorial/rb
diff options
context:
space:
mode:
authorMark Slee <mcslee@apache.org>2007-03-14 02:47:35 +0000
committerMark Slee <mcslee@apache.org>2007-03-14 02:47:35 +0000
commit7679196f1cb6a4b919917aeab065ca86b9b8ad91 (patch)
tree432f2d4425bcc5e627261ef459cf34b6b32ba57e /tutorial/rb
parent0c2dff3f5a69726e98636c091454b9b5e3ab8898 (diff)
downloadthrift-7679196f1cb6a4b919917aeab065ca86b9b8ad91.tar.gz
Various Thrift fixes, including Application Exception support in Ruby, better errror messages across languages, etc.
Reviewed By: thrift git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665058 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'tutorial/rb')
-rwxr-xr-xtutorial/rb/RubyClient.rb70
-rwxr-xr-xtutorial/rb/RubyServer.rb3
2 files changed, 40 insertions, 33 deletions
diff --git a/tutorial/rb/RubyClient.rb b/tutorial/rb/RubyClient.rb
index e0b47b635..bcf130094 100755
--- a/tutorial/rb/RubyClient.rb
+++ b/tutorial/rb/RubyClient.rb
@@ -7,37 +7,43 @@ require 'thrift/protocol/tbinaryprotocol'
require 'Calculator'
-transport = TSocket.new('localhost', 9090)
-protocol = TBinaryProtocol.new(transport)
-client = Calculator::Client.new(protocol)
-
-transport.open()
-
-client.ping()
-print "ping()\n"
-
-sum = client.add(1,1)
-print "1+1=", sum, "\n"
-
-work = Work.new()
-
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"
+
+ transport = TBufferedTransport.new(TSocket.new('localhost', 9090))
+ protocol = TBinaryProtocol.new(transport)
+ client = Calculator::Client.new(protocol)
+
+ transport.open()
+
+ client.ping()
+ print "ping()\n"
+
+ sum = client.add(1,1)
+ print "1+1=", sum, "\n"
+
+ work = Work.new()
+
+ 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
+
+ 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"
+
+ transport.close()
+
+rescue TException => tx
+ print 'TException: ', tx.message, "\n"
end
-
-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"
-
-transport.close()
diff --git a/tutorial/rb/RubyServer.rb b/tutorial/rb/RubyServer.rb
index 2e9145d7f..ea39e15df 100755
--- a/tutorial/rb/RubyServer.rb
+++ b/tutorial/rb/RubyServer.rb
@@ -71,7 +71,8 @@ end
handler = CalculatorHandler.new()
processor = Calculator::Processor.new(handler)
transport = TServerSocket.new(9090)
-server = TSimpleServer.new(processor, transport)
+transportFactory = TBufferedTransportFactory.new()
+server = TSimpleServer.new(processor, transport, transportFactory)
puts "Starting the server..."
server.serve()