box-o-sand/zeromq/hwclient.rb

30 lines
626 B
Ruby

# vim:fileencoding=utf-8:expandtab
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")
puts "requester is a #{requester.class.inspect}"
0.upto(9) do |request_nbr|
puts "Sending request #{request_nbr}"
if requester.send("Hello")
puts "Sent request, now receiving reply"
reply = requester.recv
puts "Received reply #{request_nbr}: [#{reply}]"
end
end
puts "Outside of loop now. Closing socket..."
requester.close
end
if $0 == __FILE__
main
end