Class: TcpConnectionData

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_addressObject (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

#portObject (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_bytesObject



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_bytesObject



30
31
32
# File 'lib/javonet-ruby-sdk/utils/tcp_connection_data.rb', line 30

def get_port_bytes
  [@port & 0xFF, @port >> 8]
end

#to_sObject



21
22
23
24
# File 'lib/javonet-ruby-sdk/utils/tcp_connection_data.rb', line 21

def to_s
  "#{@ip_address}:#{@port}"

end