class Glottis::Client

Client class, used to interact with the host specified.

Public Class Methods

logger() click to toggle source
# File lib/glottis/client.rb, line 11
def self.logger
  @logger ||= Logger.new(STDOUT)
end
new(host, port, opts = {}) click to toggle source
# File lib/glottis/client.rb, line 15
def initialize(host, port, opts = {})
  @host = host
  @port = port
  @outgoing = Queue.new
  @incoming = Queue.new
  Client.logger.level = opts[:verbose] ? Logger::DEBUG : Logger::WARN
end

Public Instance Methods

run() click to toggle source
# File lib/glottis/client.rb, line 23
def run
  Client.logger.info('starting...')
  Thread.abort_on_exception = true

  @handlers = [
    Handlers::ConsoleInputHandler.new(@outgoing),
    Handlers::ConsoleOutputHandler.new(@incoming),
    Handlers::RemoteInputHandler.new(@incoming, @host, @port),
    Handlers::RemoteOutputHandler.new(@outgoing, @host, @port)
  ]

  @handlers.each(&:join)
rescue Errno::ECONNREFUSED => conn_ref
  Client.logger.error("failed to connect: #{conn_ref}")
rescue StandardError => ex
  Client.logger.warn("shutting down: #{ex}")
ensure
  @handlers.each(&:cleanup)
  exit(0)
end