#!/usr/bin/ruby

require "tcpwrap"

serv = TCPServer.open(ARGV.shift || "echo")
tcpd = TCPWrapper.new("echod", serv, true, 30)
loop do
  ns = tcpd.accept
  Thread.start do
    s = ns
    while line = s.gets
      s.print(line)
    end
    s.shutdown
    s.close
  end
end
