That's better. Closing the socket is always polite.

This commit is contained in:
Dan Buch 2012-03-15 22:05:56 -04:00
parent fc2f46f05a
commit 288198d8f6

View File

@ -1,4 +1,4 @@
# vim:fileencoding=utf-8 # vim:fileencoding=utf-8:expandtab
require 'zmq' require 'zmq'
@ -8,16 +8,21 @@ def main
puts "Connecting to hello world server…" puts "Connecting to hello world server…"
requester = context.socket(ZMQ::REQ) requester = context.socket(ZMQ::REQ)
requester.connect("tcp://localhost:5555") requester.connect("tcp://localhost:5555")
puts "requester is a #{requester.class.inspect}"
0.upto(9) do |request_nbr| 0.upto(9) do |request_nbr|
puts "Sending request #{request_nbr}" puts "Sending request #{request_nbr}"
requester.send("Hello") if requester.send("Hello")
puts "Sent request, now receiving reply"
reply = requester.recv(6) reply = requester.recv
puts "Received reply #{request_nbr}: [#{reply}]" puts "Received reply #{request_nbr}: [#{reply}]"
end end
end end
puts "Outside of loop now. Closing socket..."
requester.close
end
if $0 == __FILE__ if $0 == __FILE__
main main