Sha256: ba7d9c0d030859aa1a72027f5f3404a244f2697a38115d1220817d0fbf9bb623
Contents?: true
Size: 873 Bytes
Versions: 1
Compression:
Stored size: 873 Bytes
Contents
require 'socket' require_relative 'tattler' module Buschtelefon class NetTattler < Tattler attr_accessor :port def initialize(port: nil) super() @port = port || rand(1025..65365) # TODO: use port 0 end def listen(&_callback) puts "Started UDP server on #{@port}..." Socket.udp_server_loop(@port) do |message, message_source| puts "Got \"#{message}\" from #{message_source}" if message == "\x05" handle_knowledge_inquiry(message_source) else handle_incoming_message(message) yield(message) if block_given? end end end private def handle_incoming_message(message) feed(Gossip.new(message)) end def handle_knowledge_inquiry(message_source) transfer_knowledge(RemoteTattler.new(message_source.local_address)) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
buschtelefon-0.2.0 | lib/buschtelefon/net_tattler.rb |