Class: UnixSocks::Message

Inherits:
JSON::GenericObject
  • Object
show all
Defined in:
lib/unix_socks/message.rb

Overview

Represents a message sent or received over a Unix socket, extending JSON::GenericObject for dynamic access to message attributes.

Instance Method Summary collapse

Instance Method Details

#disconnectObject

Disconnects the socket connection.

Closes the underlying socket, effectively ending the communication session.



10
11
12
# File 'lib/unix_socks/message.rb', line 10

def disconnect
  socket.close
end

#respond(answer) ⇒ UnixSocks::Message

The respond method sends a response back to the client over the Unix socket connection.

It first converts the provided answer into JSON format, and then writes it to the socket using socket.puts.

Parameters:

  • answer (Object)

    The response to be sent back to the client.

Returns:



23
24
25
26
27
28
29
# File 'lib/unix_socks/message.rb', line 23

def respond(answer)
  answer = answer.ask_and_send(:to_json) or
    raise TypeError, 'needs to be convertibla to JSON'
  socket.puts answer
rescue Errno::EPIPE
  self
end