Class: Hypertube::Utils::TcpConnectionData
- Inherits:
-
ConnectionData
- Object
- ConnectionData
- Hypertube::Utils::TcpConnectionData
- Defined in:
- lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb
Constant Summary
Constants inherited from ConnectionData
ConnectionData::THREAD_LOCAL_HEADERS_KEY
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#ip_address ⇒ Object
readonly
Returns the value of attribute ip_address.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #connection_type ⇒ Object
- #get_address_bytes ⇒ Object
- #get_port_bytes ⇒ Object
-
#initialize(hostname) ⇒ TcpConnectionData
constructor
A new instance of TcpConnectionData.
- #serialize_connection_data ⇒ Object
- #to_s ⇒ Object
Methods inherited from ConnectionData
#get_headers, #get_thread_local_headers, #set_headers, #set_thread_local_headers, #to_canonical_key
Constructor Details
#initialize(hostname) ⇒ TcpConnectionData
Returns a new instance of TcpConnectionData.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 9 def initialize(hostname) super() host_only, port = parse_hostname(hostname) @hostname = "#{host_only}:#{port}" @port = port if host_only == 'localhost' @ip_address = '127.0.0.1' else begin @ip_address = IPSocket.getaddress(host_only) rescue SocketError raise 'Unable to resolve hostname to an IP address.' end end end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
7 8 9 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 7 def hostname @hostname end |
#ip_address ⇒ Object (readonly)
Returns the value of attribute ip_address.
7 8 9 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 7 def ip_address @ip_address end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 7 def port @port end |
Instance Method Details
#connection_type ⇒ Object
25 26 27 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 25 def connection_type ConnectionType::TCP end |
#get_address_bytes ⇒ Object
33 34 35 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 33 def get_address_bytes @ip_address.split('.').map(&:to_i) end |
#get_port_bytes ⇒ Object
37 38 39 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 37 def get_port_bytes [@port & 0xFF, @port >> 8] end |
#serialize_connection_data ⇒ Object
41 42 43 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 41 def serialize_connection_data [Hypertube::Utils::ConnectionType::TCP] + get_address_bytes + get_port_bytes end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/hypertube-ruby-sdk/utils/tcp_connection_data.rb', line 29 def to_s "tcp|#{@hostname}" end |