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