-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtaskwork2.rb
34 lines (28 loc) · 828 Bytes
/
taskwork2.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env ruby
require 'rbczmq'
require_relative 'zmq-additions'
context = ZMQ::Context.new
receiver = context.socket(ZMQ::PULL)
receiver.connect("tcp://localhost:5557")
sender = context.socket(ZMQ::PUSH)
sender.connect("tcp://localhost:5558")
controller = context.socket(ZMQ::SUB)
controller.connect("tcp://localhost:5559")
controller.subscribe("")
poller = ZMQ::Poller.new
receiver_poll_item = ZMQ::Pollitem.new(receiver, ZMQ::POLLIN)
controller_poll_item = ZMQ::Pollitem.new(controller, ZMQ::POLLIN)
poller.register(receiver_poll_item)
poller.register(controller_poll_item)
loop do
poller.poll(-1) # indefinite timeout
if poller.readables.include? receiver
s = receiver.recv
print "#{s}."
sleep(s.to_i/1000.0)
sender.send("")
end
if poller.readables.include? controller
break
end
end