Class: Alo7::Net::Client

Inherits:
Connection show all
Defined in:
lib/alo7/net/client.rb

Overview

This is a class that provides the client logics.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Connection

#await, #disconnect, #initialize, #send_data

Methods included from Alo7::Net::Connection::Callbacks

#connection_completed, #post_init, #receive_data, #unbind

Constructor Details

This class inherits a constructor from Alo7::Net::Connection

Class Method Details

.connect(host, port, *args) ⇒ Client

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

Parameters:

  • host (String)

    host to connect to

  • port (Integer)

    port to connect to

  • args

    passed to the initializer of the client

Returns:

  • (Client)

    the initiated client instance


16
17
18
19
# 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

Instance Method Details

#reconnect(host, port) ⇒ self

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

Parameters:

  • host (String)

    host to connect to

  • port (Integer)

    port to connect to

Returns:

  • (self)

26
27
28
29
# File 'lib/alo7/net/client.rb', line 26

def reconnect(host, port)
  Net.reconnect self, host, port
  self.class.await_connect self
end