lib/toycol/client.rb in toycol-0.3.0 vs lib/toycol/client.rb in toycol-0.3.1

- old
+ new

@@ -1,21 +1,22 @@ # frozen_string_literal: true -require "socket" - module Toycol class Client + extend Helper + @port = 9292 + @host = "localhost" CHUNK_SIZE = 1024 * 16 class << self - attr_writer :port + attr_writer :port, :host def execute!(request_message, &block) - socket = TCPSocket.new("localhost", @port) + socket = TCPSocket.new(@host, @port) socket.write(request_message) - puts "[Toycol] Sent request message: #{request_message}\n---" + logger "Sent request message: #{request_message}\n---" response_message = [] response_message << socket.readpartial(CHUNK_SIZE) until socket.eof? response_message = response_message.join @@ -27,10 +28,10 @@ private def default_proc proc do |message| - puts "[Toycol] Received response message:\n\n" + logger "Received response message:\n\n" puts message end end end end