Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # receive.rb -----
- require 'socket'
- require 'ipaddr'
- MULTICAST_ADDR = "225.4.5.7"
- PORT = 28960
- ip = IPAddr.new(MULTICAST_ADDR).hton + IPAddr.new("0.0.0.0").hton
- sock = UDPSocket.new
- sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, ip)
- sock.bind(Socket::INADDR_ANY, PORT)
- loop do
- msg, info = sock.recvfrom(1024)
- puts "MSG: #{msg} from #{info[2]} (#{info[3]})/#{info[1]} len #{msg.size}"
- end
- # send.rb ------
- require 'ipaddr'
- require 'socket'
- MULTICAST_ADDR = "225.4.5.7"
- PORT= 28960
- begin
- socket = UDPSocket.open
- socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_TTL, [1].pack('i'))
- socket.send(ARGV.join(' '), 0, MULTICAST_ADDR, PORT)
- ensure
- socket.close
- end
Add Comment
Please, Sign In to add comment