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.


328
329
330
331
# File 'lib/minitcp.rb', line 328

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

Class Method Details

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


322
323
324
325
326
327
# File 'lib/minitcp.rb', line 322

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


332
333
334
335
336
337
338
339
# File 'lib/minitcp.rb', line 332

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