Sha256: 6046aa884e1c084a7b8d76f9587cb3c44dc829d996a1ce7dd347af53a3757809

Contents?: true

Size: 687 Bytes

Versions: 3

Compression:

Stored size: 687 Bytes

Contents

require "socket"

module Buschtelefon
  # No need to inheritance from Tattler because not all its features are available here (only #feed)
  class RemoteTattler
    attr_reader :host, :port

    def initialize(host:, port:, outbound_socket: UDPSocket.new)
      @host = host
      @port = port
      @outbound_socket = outbound_socket
    end

    def feed(gossip)
      # puts "#{@outbound_socket.local_address.ip_port} sending #{JSON.parse(gossip.message)['number']} to #{@port}"
      @outbound_socket.send(gossip.message, 0, @host, @port)
    end

    def inquire
      @outbound_socket.send("\x05", 0, @host, @port)
    end

    def to_s
      "#{@host}:#{@port}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
buschtelefon-0.5.0 lib/buschtelefon/remote_tattler.rb
buschtelefon-0.4.2 lib/buschtelefon/remote_tattler.rb
buschtelefon-0.4.1 lib/buschtelefon/remote_tattler.rb