class UDPMulticast

Public Class Methods

new(multicast_addr = '225.4.5.6', port = 553, ttl = 1) click to toggle source
# File lib/udpmulticast.rb, line 5
def initialize(multicast_addr = '225.4.5.6', port = 553, ttl = 1)
  @multicast_addr = multicast_addr
  @port = port
  @ttl = ttl
  @server = nil
  @client = nil
  client_socket
end

Public Instance Methods

client() click to toggle source
# File lib/udpmulticast.rb, line 30
def client
  @client
end
client_socket() click to toggle source
# File lib/udpmulticast.rb, line 42
def client_socket
  open_socket
  socket_opt @client, Socket::IP_MULTICAST_TTL, @ttl
  socket_opt @client, Socket::IP_TTL, @ttl
end
multicast_addr() click to toggle source
# File lib/udpmulticast.rb, line 26
def multicast_addr
  @multicast_addr
end
port() click to toggle source
# File lib/udpmulticast.rb, line 22
def port
  @port
end
run!() click to toggle source
# File lib/udpmulticast.rb, line 34
def run!
  create_socket
  socket_opt @server, Socket::IP_ADD_MEMBERSHIP, multicast_member
  socket_opt @server, Socket::IP_MULTICAST_TTL, @ttl
  socket_opt @server, Socket::IP_TTL, @ttl
  bind
end
server() click to toggle source
# File lib/udpmulticast.rb, line 14
def server
  @server
end
ttl() click to toggle source
# File lib/udpmulticast.rb, line 18
def ttl
  @ttl
end

Private Instance Methods

bind() click to toggle source
# File lib/udpmulticast.rb, line 66
def bind
  @server.bind Socket::INADDR_ANY, @port
end
create_socket() click to toggle source
# File lib/udpmulticast.rb, line 54
def create_socket
  @server = UDPSocket.new
end
multicast_member() click to toggle source
# File lib/udpmulticast.rb, line 50
def multicast_member
  IPAddr.new(@multicast_addr).hton + IPAddr.new('0.0.0.0').hton
end
open_socket() click to toggle source
# File lib/udpmulticast.rb, line 58
def open_socket
  @client = UDPSocket.open
end
socket_opt(socket, opt, val) click to toggle source
# File lib/udpmulticast.rb, line 62
def socket_opt(socket, opt, val)
  socket.setsockopt Socket::IPPROTO_IP, opt, val
end