Class: TcpConnectionData
- Inherits:
-
Object
- Object
- TcpConnectionData
- Defined in:
- lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb
Instance Attribute Summary collapse
-
#ip_address ⇒ Object
readonly
Returns the value of attribute ip_address.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #get_address_bytes ⇒ Object
- #get_port_bytes ⇒ Object
-
#initialize(hostname, port) ⇒ TcpConnectionData
constructor
A new instance of TcpConnectionData.
- #serialize_connection_data ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(hostname, port) ⇒ TcpConnectionData
Returns a new instance of TcpConnectionData.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 6 def initialize(hostname, port) @port = port if hostname == 'localhost' @ip_address = '127.0.0.1' else begin @ip_address = IPSocket.getaddress(hostname) rescue SocketError raise 'Unable to resolve hostname to an IP address.' end end end |
Instance Attribute Details
#ip_address ⇒ Object (readonly)
Returns the value of attribute ip_address.
4 5 6 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 4 def ip_address @ip_address end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
4 5 6 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 4 def port @port end |
Instance Method Details
#==(other) ⇒ Object
19 20 21 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 19 def ==(other) other.is_a?(TcpConnectionData) && @ip_address == other.ip_address && @port == other.port end |
#get_address_bytes ⇒ Object
27 28 29 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 27 def get_address_bytes @ip_address.split('.').map(&:to_i) end |
#get_port_bytes ⇒ Object
31 32 33 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 31 def get_port_bytes [@port & 0xFF, @port >> 8] end |
#serialize_connection_data ⇒ Object
35 36 37 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 35 def serialize_connection_data [ConnectionType::TCP] + get_address_bytes + get_port_bytes end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 23 def to_s "#{@ip_address}:#{@port}" end |