Class: ProconBypassMan::ProconDisplay::Server

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

Constant Summary collapse

PORT =
9900

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



13
14
15
# File 'lib/procon_bypass_man/procon_display/server.rb', line 13

def initialize
  @server = TCPServer.new('0.0.0.0', PORT)
end

Class Method Details

.start!Object



7
8
9
10
11
# File 'lib/procon_bypass_man/procon_display/server.rb', line 7

def self.start!
  Thread.new do
    new.start_with_foreground
  end
end

Instance Method Details

#start_with_foregroundObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/procon_bypass_man/procon_display/server.rb', line 17

def start_with_foreground
  loop do
    conn = @server.accept
    response = ServerApp.new(
      HttpRequest.parse(conn).to_hash
    ).call
    conn.write(response)
    conn.close
  end
rescue Errno::EADDRINUSE => e
  ProconBypassMan::SendErrorCommand.execute(error: e)
rescue => e
  ProconBypassMan::SendErrorCommand.execute(error: e)
  retry
end