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

require 'socket'

ss = TCPServer.open(3456)
all = [ss]
csn = []
loop do
  inputs = IO.select(all)
  if inputs != nil 
    sock = inputs[0][0]
    if sock == ss
	cs = ss.accept
	all << cs
	csn << cs
    else
	msg = sock.gets.chomp
	csn.each{|csx|
	    if csx != sock
		csx.puts msg
	    end
	}
    end
  end
end