Sha256: 919e665c15842a141d9b3a39ef06865c029dcaa1e8e148019126dbe523cef75c

Contents?: true

Size: 753 Bytes

Versions: 6

Compression:

Stored size: 753 Bytes

Contents

class TcpConnectionData
  attr_reader :ip_address, :port

  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

  def ==(other)
    other.is_a?(TcpConnectionData) && @ip_address == other.ip_address && @port == other.port
  end

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

  end

  def get_address_bytes
    @ip_address.split(".").map(&:to_i)
  end

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

  def serialize_connection_data
    [ConnectionType::TCP] + get_address_bytes + get_port_bytes
  end
end

Version data entries

6 entries across 3 versions & 1 rubygems

Version Path
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/utils/tcp_connection_data.rb
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/utils/tcp_connection_data.rb
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/utils/tcp_connection_data.rb
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/utils/tcp_connection_data.rb
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/Binaries/Ruby/Linux/X64/utils/tcp_connection_data.rb
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/Binaries/Ruby/MacOs/X64/utils/tcp_connection_data.rb