Class: Multicast::Sender

Inherits:
Object
  • Object
show all
Defined in:
lib/multicast/sender.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Sender

Returns a new instance of Sender.



5
6
7
8
# File 'lib/multicast/sender.rb', line 5

def initialize(opts={})
  @group  = opts[:group]
  @port   = opts[:port]
end

Instance Attribute Details

#groupObject

Returns the value of attribute group.



3
4
5
# File 'lib/multicast/sender.rb', line 3

def group
  @group
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'lib/multicast/sender.rb', line 3

def port
  @port
end

Instance Method Details

#send(message) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/multicast/sender.rb', line 10

def send(message)
  
  begin
    socket = UDPSocket.open
    socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_TTL, [1].pack('i'))
    socket.send(message, 0, @group, @port)
  ensure
    socket.close 
  end
end