summaryrefslogtreecommitdiff
path: root/nanomsg/slave.rb
blob: 3183df846a655c71a37e6252fbd190d2af148169 (plain)
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
require 'nanomsg'

sock = NanoMsg::PairSocket.new
sock.connect "tcp://127.0.0.1:#{ARGV[0]}"

sock.recv
sleep 1
sock.send "hello there"

i = 0
while true
  msg = sock.recv
  if msg == "shutdown"
    sock.send "shutting down"
    break
  end
  me, id, input = msg.split
  sleep 1
  sock.send "#{me} answers #{id}"
  sleep 1
  sock.send "----2#{i}----" if i%2==0
  sleep 1
  i += 1
end