Class: Toycol::Client

Inherits:
Object
  • Object
show all
Extended by:
Helper
Defined in:
lib/toycol/client.rb

Constant Summary collapse

CHUNK_SIZE =
1024 * 16

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Helper

logger

Class Attribute Details

.host=(value) ⇒ Object (writeonly)

Sets the attribute host

Parameters:

  • value

    the value to set the attribute host to.



12
13
14
# File 'lib/toycol/client.rb', line 12

def host=(value)
  @host = value
end

.port=(value) ⇒ Object (writeonly)

Sets the attribute port

Parameters:

  • value

    the value to set the attribute port to.



12
13
14
# File 'lib/toycol/client.rb', line 12

def port=(value)
  @port = value
end

Class Method Details

.execute!(request_message, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/toycol/client.rb', line 14

def execute!(request_message, &block)
  socket = TCPSocket.new(@host, @port)
  socket.write(request_message)
  logger "Sent request message: #{request_message}\n---"

  response_message = []
  response_message << socket.readpartial(CHUNK_SIZE) until socket.eof?
  response_message = response_message.join

  block ||= default_proc
  block.call(response_message)
ensure
  socket.close
end