# work0801.rb
# žÁ÷¥µ¡¼¥Ð

require 'socket'

ss = TCPServer.open(3456)
max = 5
puts "waiting for "+max.to_s+" clients"
csn = []
max.times{|i|
    csn[i] = ss.accept
}
puts "accepted"
loop do
  inputs = IO.select(csn)
  if inputs != nil 
    cs = inputs[0][0]
    msg = cs.gets.chomp
    csn.each{|csx|
        if csx != cs
	    csx.puts msg
	end
    }
  end
end