Class: Pandemic::ClientSide::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/pandemic/client_side/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, key) ⇒ Connection

Returns a new instance of Connection.



5
6
7
8
# File 'lib/pandemic/client_side/connection.rb', line 5

def initialize(host, port, key)
  @host, @port, @key = host, port, key
  connect
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/pandemic/client_side/connection.rb', line 4

def key
  @key
end

#socketObject (readonly)

Returns the value of attribute socket.



4
5
6
# File 'lib/pandemic/client_side/connection.rb', line 4

def socket
  @socket
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/pandemic/client_side/connection.rb', line 10

def alive?
  @socket && !@socket.closed?
end

#died!Object



18
19
20
21
# File 'lib/pandemic/client_side/connection.rb', line 18

def died!
  @socket.close if self.alive?
  @socket = nil
end

#ensure_alive!Object



14
15
16
# File 'lib/pandemic/client_side/connection.rb', line 14

def ensure_alive!
  connect unless self.alive?
end