Class: DebugServer::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/debugserver/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



23
24
25
26
# File 'lib/debugserver/server.rb', line 23

def initialize
  @socket = nil
  @sessions = []
end

Instance Attribute Details

#sessionsObject (readonly)

Returns the value of attribute sessions.



10
11
12
# File 'lib/debugserver/server.rb', line 10

def sessions
  @sessions
end

#socketObject (readonly)

Returns the value of attribute socket.



9
10
11
# File 'lib/debugserver/server.rb', line 9

def socket
  @socket
end

Instance Method Details

#close_session(s) ⇒ Object

close existing session on client disconnect



29
30
31
# File 'lib/debugserver/server.rb', line 29

def close_session(s)
  @sessions.delete(s)
end

#startObject

start server execution



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/debugserver/server.rb', line 34

def start
  config = DebugServer.config
  
  system('clear')
  puts "Starting debug server on #{config[:host]}:#{config[:port]}..."
  
  begin
    EventMachine::run do
      EventMachine.epoll  
      @socket = EventMachine::start_server(config[:host], config[:port], Session) do |s|
        init_session(s)
      end
    end
  rescue Interrupt
    stop
  rescue RuntimeError => err
    puts "Runtime error: #{err.message}"
    stop
  end
end

#stopObject

stop server executions



56
57
58
59
# File 'lib/debugserver/server.rb', line 56

def stop
  puts "Exiting..."
  exit(0)
end