Class: Puggernaut::Server

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/puggernaut/server.rb,
lib/puggernaut/server/tcp.rb,
lib/puggernaut/server/http.rb,
lib/puggernaut/server/shared.rb,
lib/puggernaut/server/channel.rb,
lib/puggernaut/server/websocket.rb

Defined Under Namespace

Modules: Http, Shared, Tcp Classes: Channel, Websocket

Instance Method Summary collapse

Methods included from Logger

#logger, logger

Constructor Details

#initialize(http_port = 8100, tcp_port = http_port.to_i+1, ws_port = tcp_port.to_i+1) ⇒ Server

Returns a new instance of Server.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/puggernaut/server.rb', line 12

def initialize(http_port=8100, tcp_port=http_port.to_i+1, ws_port=tcp_port.to_i+1)
  puts "\nPuggernaut is starting on #{http_port} (Long Poll HTTP), #{tcp_port} (Puggernaut TCP), and #{ws_port} (WebSocket TCP)"
  puts "*snort*\n\n"

  begin
    Channel.channels = []
    EM.epoll if EM.epoll?
    EM.run do
      logger.info "Server#initialize - Starting HTTP - #{http_port}"
      EM.start_server '0.0.0.0', http_port, Http
      
      logger.info "Server#initialize - Starting TCP - #{tcp_port}"
      EM.start_server '0.0.0.0', tcp_port, Tcp
      
      logger.info "Server#initialize - Starting WebSocket - #{ws_port}"
      Websocket.new '0.0.0.0', ws_port
      
      errors = 0
    end
  rescue Interrupt
    logger.info "Server#initialize - Shutting down"
    exit
  rescue
    logger.error "Server#initialize - Error - #{$!.message}"
    logger.error "\t" + $!.backtrace.join("\n\t")
  end
end