class Alo7::Net::Client

This is a class that provides the client logics.

Public Class Methods

await_connect(connection) click to toggle source

@private

# File lib/alo7/net/client.rb, line 47
def await_connect(connection)
  defer = Defer.new
  connection.impl.connect_defer = defer
  Net.await defer
  connection
end
connect(host, port, *args) click to toggle source

Initiate a TCP connection to a remote server and set up event handling for the connection.

@param host [String] host to connect to @param port [Integer] port to connect to @param args passed to the initializer of the client @return [Client] the initiated client instance

# File lib/alo7/net/client.rb, line 16
def self.connect(host, port, *args)
  connection = Net.connect self, host, port, *args
  await_connect connection
end

Public Instance Methods

reconnect(host, port) click to toggle source

Connect to a given host/port and re-use the instance.

@param host [String] host to connect to @param port [Integer] port to connect to @return [self]

@raise if another {#reconnect} is under progress

# File lib/alo7/net/client.rb, line 28
def reconnect(host, port)
  raise AnotherReconnectingUnderProgress.new 'another reconnecting is under progress' if impl.connect_defer
  Net.reconnect self, host, port
  self.class.await_connect self
end