Class: PingPongPear::Listener
- Inherits:
-
Object
- Object
- PingPongPear::Listener
- Defined in:
- lib/ping_pong_pear.rb
Instance Method Summary collapse
-
#initialize ⇒ Listener
constructor
A new instance of Listener.
- #start ⇒ Object
Constructor Details
#initialize ⇒ Listener
Returns a new instance of Listener.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ping_pong_pear.rb', line 53 def initialize @multicast_addr = MULTICAST_ADDR @bind_addr = "0.0.0.0" @port = UDP_PORT @socket = UDPSocket.new membership = IPAddr.new(@multicast_addr).hton + IPAddr.new(@bind_addr).hton @socket.setsockopt :IPPROTO_IP, :IP_ADD_MEMBERSHIP, membership @socket.setsockopt :SOL_SOCKET, :SO_REUSEPORT, 1 @socket.bind @bind_addr, @port end |
Instance Method Details
#start ⇒ Object
67 68 69 70 71 72 |
# File 'lib/ping_pong_pear.rb', line 67 def start loop do , _ = @socket.recvfrom 1024 yield JSON.parse() end end |