require 'tools.rb' module Secure class Client def initialize(socket) @socket=socket @data="" end def send(*m) end def register(&b) end def run @thread=Thread.new { begin loop do @data+=@socket.read(1024) check end rescue Exception=>e log e,e.backtrace end } end private def check end end class Server attr_reader :clients def initialize(port,host="localhost") @port=port @host=host addr= Socket.pack_sockaddr_in( @port,@host) @server=TCPServer.new(port,addr) @clients=[] @mainThread=nil @mutex=Mutex.new end def clients @mutex.synchronize { @clients.dup } end def kill @mainThread.kill if @mainThread end def run @mainThread=Thread.new { client=@server.accept c=Client.new(client) @mutex.synchronize { @clients<e log e @mutex.synchronize { @clients.delete(c) } end } end end end