Class: Necro::CommandListener::Server

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

Constant Summary collapse

SOCKET_PATH =
"/tmp/necro"

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



7
8
9
10
11
12
13
14
15
16
# File 'lib/necro/command_listener/server.rb', line 7

def initialize
  @open_clients = []
  clean_old_socket()
  UNIXServer.open(SOCKET_PATH) do |client|
    loop do
      client_socket = client.accept
      process_client(client_socket)
    end
  end
end

Instance Method Details

#clean_old_socketObject



18
19
20
21
22
# File 'lib/necro/command_listener/server.rb', line 18

def clean_old_socket
  if File.exists?(SOCKET_PATH)
    FileUtils.rm(SOCKET_PATH, :force => true)
  end
end

#process_client(client_socket) ⇒ Object



24
25
26
27
# File 'lib/necro/command_listener/server.rb', line 24

def process_client(client_socket)
  client = Necro::CommandListener::Client.new(client_socket)
  client.read_and_execute
end