Class: MServer

Inherits:
GServer
  • Object
show all
Defined in:
lib/minitcp.rb

Overview

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} }

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port, host, max = 1, &b) ⇒ MServer

Returns a new instance of MServer.



340
341
342
343
# File 'lib/minitcp.rb', line 340

def initialize(port,host,max=1,&b)
  super(port,host,max,nil)
  @bloc=b
end

Class Method Details

.service(port, host, max, &b) ⇒ Object



334
335
336
337
338
339
# 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

Instance Method Details

#serve(io) ⇒ Object



344
345
346
347
348
349
350
351
# 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