Class: Del::SocketServer

Inherits:
Object
  • Object
show all
Defined in:
lib/del/socket_server.rb

Overview

A Socket server for client/server communication overs a UNIX socket.

Instance Method Summary collapse

Constructor Details

#initialize(socket_file:) ⇒ SocketServer

Returns a new instance of SocketServer.



7
8
9
# File 'lib/del/socket_server.rb', line 7

def initialize(socket_file:)
  @connection = SocketConnection.new(path: socket_file)
end

Instance Method Details

#run(robot) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/del/socket_server.rb', line 11

def run(robot)
  loop do
    @connection.on_receive do |socket|
      line = socket.readline
      Del.logger.debug(line)
      socket.write(robot.execute(JSON.parse(line)))
    end
  end
end