Class: Hubeye::Client::Connection
- Inherits:
-
Object
- Object
- Hubeye::Client::Connection
- Defined in:
- lib/hubeye/client/connection.rb
Instance Attribute Summary collapse
-
#local ⇒ Object
readonly
Returns the value of attribute local.
-
#peer ⇒ Object
readonly
Returns the value of attribute peer.
-
#peeraddr ⇒ Object
readonly
Returns the value of attribute peeraddr.
-
#s ⇒ Object
readonly
Returns the value of attribute s.
Instance Method Summary collapse
-
#initialize(host, port) ⇒ Connection
constructor
A new instance of Connection.
- #receive_welcome ⇒ Object
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
#local ⇒ Object (readonly)
Returns the value of attribute local.
6 7 8 |
# File 'lib/hubeye/client/connection.rb', line 6 def local @local end |
#peer ⇒ Object (readonly)
Returns the value of attribute peer.
6 7 8 |
# File 'lib/hubeye/client/connection.rb', line 6 def peer @peer end |
#peeraddr ⇒ Object (readonly)
Returns the value of attribute peeraddr.
6 7 8 |
# File 'lib/hubeye/client/connection.rb', line 6 def peeraddr @peeraddr end |
#s ⇒ Object (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_welcome ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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!" exit 1 rescue EOFError @retried ||= -1 @retried += 1 retry unless @retried >= 1 end end |