Class: Hubeye::Client::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/hubeye/client/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ Connection

Returns a new instance of Connection.



8
9
10
11
12
13
14
15
16
17
# File 'lib/hubeye/client/connection.rb', line 8

def initialize(host, port)
  _begin do
    print "Connecting..."
    @s = TCPSocket.open(host, port)
    @s.sync = false
    @local, @peer = @s.addr, @s.peeraddr
    puts "Done" if @s
    puts "Connected to #{peer[2]}:#{peer[1]} using port #{local[1]}"
  end
end

Instance Attribute Details

#localObject (readonly)

Returns the value of attribute local.



6
7
8
# File 'lib/hubeye/client/connection.rb', line 6

def local
  @local
end

#peerObject (readonly)

Returns the value of attribute peer.



6
7
8
# File 'lib/hubeye/client/connection.rb', line 6

def peer
  @peer
end

#peeraddrObject (readonly)

Returns the value of attribute peeraddr.



6
7
8
# File 'lib/hubeye/client/connection.rb', line 6

def peeraddr
  @peeraddr
end

#sObject (readonly)

Returns the value of attribute s.



6
7
8
# File 'lib/hubeye/client/connection.rb', line 6

def s
  @s
end

Instance Method Details

#receive_welcomeObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hubeye/client/connection.rb', line 19

def receive_welcome
  begin
    mesg = @s.read_all
    puts mesg
  rescue SystemCallError, NoMethodError
    puts "The server's not running!"
  rescue EOFError
    @retried ||= -1
    @retried += 1
    retry unless @retried >= 1
  end
end