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