Class: Backport::Client
- Inherits:
-
Object
- Object
- Backport::Client
- Includes:
- Observable
- Defined in:
- lib/backport/client.rb
Overview
A client connected to a connectable Backport server.
Instance Attribute Summary collapse
- #adapter ⇒ Adapter readonly
Instance Method Summary collapse
-
#initialize(input, output, adapter, remote = {}) ⇒ Client
constructor
A new instance of Client.
-
#start ⇒ void
(also: #run)
Start running the client.
-
#stop ⇒ void
Close the client connection.
-
#stopped? ⇒ Boolean
True if the client is stopped.
-
#tick ⇒ void
Handle a tick from the server.
Constructor Details
#initialize(input, output, adapter, remote = {}) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 |
# File 'lib/backport/client.rb', line 16 def initialize input, output, adapter, remote = {} @in = input @out = output @mutex = Mutex.new @adapter = make_adapter(adapter, remote) @stopped = true @buffer = '' end |
Instance Attribute Details
#adapter ⇒ Adapter (readonly)
10 11 12 |
# File 'lib/backport/client.rb', line 10 def adapter @adapter end |
Instance Method Details
#start ⇒ void Also known as: run
This method returns an undefined value.
Start running the client. This method will start the thread that reads client input from IO.
50 51 52 53 54 55 |
# File 'lib/backport/client.rb', line 50 def start return unless stopped? @stopped = false @adapter.opening run_input_thread end |
#stop ⇒ void
The client sets #stopped? to true and runs the adapter’s #closing
This method returns an undefined value.
Close the client connection.
callback. The server is responsible for implementation details like closing the client’s socket.
38 39 40 41 42 43 44 |
# File 'lib/backport/client.rb', line 38 def stop return if stopped? @adapter.closing @stopped = true changed notify_observers self end |
#stopped? ⇒ Boolean
True if the client is stopped.
27 28 29 |
# File 'lib/backport/client.rb', line 27 def stopped? @stopped ||= false end |
#tick ⇒ void
This method returns an undefined value.
Handle a tick from the server. This method will check for client input and update the adapter accordingly, or stop the client if the adapter is closed.
64 65 66 67 |
# File 'lib/backport/client.rb', line 64 def tick input = read @adapter.receiving input unless input.nil? end |