# usage: ruby pub.rb CHAN USERNAME
#
#     ruby pub.rb rubyonrails technoweenie
#
#
# binds a PUB socket to tcp://*:5555

require 'rubygems'
require 'zmq'

context = ZMQ::Context.new
chan    = ARGV[0]
user    = ARGV[1]
pub     = context.socket ZMQ::PUB
pub.setsockopt ZMQ::IDENTITY, "#{chan}-#{user}"

pub.bind 'tcp://*:5555'

while msg = STDIN.gets
  msg.strip!
  pub.send "#{chan} #{user} #{msg}"
end