Class: ESM::Connection::Server

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/esm/connection/server.rb

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/esm/connection/server.rb', line 14

def initialize
  @server = ServerSocket.new(
    TCPServer.new("0.0.0.0", ESM.config.ports.connection_server)
  )

  @config = ESM.config.connection_server

  @connection_manager = ConnectionManager.new(
    lobby_timeout: @config.lobby_timeout,
    heartbeat_timeout: @config.heartbeat_timeout
  )
end

Instance Method Details

#client(id) ⇒ Object



43
44
45
# File 'lib/esm/connection/server.rb', line 43

def client(id)
  @connection_manager.find(id)
end

#startObject



27
28
29
30
31
32
33
34
# File 'lib/esm/connection/server.rb', line 27

def start
  execution_interval = @config.connection_check

  @task = Concurrent::TimerTask.execute(execution_interval:) { on_connect }
  @task.add_observer(ErrorHandler.new)

  info!(status: :started)
end

#stopObject



36
37
38
39
40
41
# File 'lib/esm/connection/server.rb', line 36

def stop
  @connection_manager.stop

  @server.close
  @task.shutdown
end