Class: TcpConnectionData
- Inherits:
-
Object
- Object
- TcpConnectionData
- Defined in:
- lib/javonet-ruby-sdk/utils/tcp_connection_data.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/utils/tcp_connection_data.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/utils/tcp_connection_data.rb,
lib/javonet-ruby-sdk/Binaries/Ruby/Windows/X64/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.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/javonet-ruby-sdk/utils/tcp_connection_data.rb', line 4 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.
2 3 4 |
# File 'lib/javonet-ruby-sdk/utils/tcp_connection_data.rb', line 2 def ip_address @ip_address end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
2 3 4 |
# File 'lib/javonet-ruby-sdk/utils/tcp_connection_data.rb', line 2 def port @port end |
Instance Method Details
#==(other) ⇒ Object
17 18 19 |
# File 'lib/javonet-ruby-sdk/utils/tcp_connection_data.rb', line 17 def ==(other) other.is_a?(TcpConnectionData) && @ip_address == other.ip_address && @port == other.port end |
#get_address_bytes ⇒ Object
26 27 28 |
# File 'lib/javonet-ruby-sdk/utils/tcp_connection_data.rb', line 26 def get_address_bytes @ip_address.split(".").map(&:to_i) end |
#get_port_bytes ⇒ Object
30 31 32 |
# File 'lib/javonet-ruby-sdk/utils/tcp_connection_data.rb', line 30 def get_port_bytes [@port & 0xFF, @port >> 8] end |
#serialize_connection_data ⇒ Object
34 35 36 |
# File 'lib/javonet-ruby-sdk/utils/tcp_connection_data.rb', line 34 def serialize_connection_data [ConnectionType::TCP] + get_address_bytes + get_port_bytes end |
#to_s ⇒ Object
21 22 23 24 |
# File 'lib/javonet-ruby-sdk/utils/tcp_connection_data.rb', line 21 def to_s "#{@ip_address}:#{@port}" end |