class MServer

Run a TCP serveur, with a max connection simultaneous, When connection succes, call the bloc given with socket (extended by SocketReactive).

MServer.new( “8080” , “0.0.0.0” ,1) { |socket| loop { p socket.gets} }

Public Class Methods

new(port,host,max=1,&b) click to toggle source
Calls superclass method
# File lib/minitcp.rb, line 340
def initialize(port,host,max=1,&b)
  super(port,host,max,nil)
  @bloc=b
end
service(port,host,max,&b) click to toggle source
# File lib/minitcp.rb, line 334
def self.service(port,host,max,&b)
  srv=new(port,host,max,&b)
  srv.audit = false
  srv.start
  srv
end

Public Instance Methods

serve( io ) click to toggle source
# File lib/minitcp.rb, line 344
def serve( io )
  SocketReactive::make_socket_reactive(io)
  begin
    @bloc.call(io)
  rescue Exception => e
    puts  "Error in Mserver block: #{e} :\n  #{e.backtrace.join("\n  ")}"
  end
end