Guest User

Untitled

a guest
Nov 24th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. # receive.rb -----
  2.  
  3. require 'socket'
  4. require 'ipaddr'
  5.  
  6. MULTICAST_ADDR = "225.4.5.7"
  7. PORT = 28960
  8.  
  9. ip = IPAddr.new(MULTICAST_ADDR).hton + IPAddr.new("0.0.0.0").hton
  10.  
  11. sock = UDPSocket.new
  12. sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, ip)
  13. sock.bind(Socket::INADDR_ANY, PORT)
  14.  
  15. loop do
  16. msg, info = sock.recvfrom(1024)
  17. puts "MSG: #{msg} from #{info[2]} (#{info[3]})/#{info[1]} len #{msg.size}"
  18. end
  19.  
  20.  
  21. # send.rb ------
  22.  
  23. require 'ipaddr'
  24. require 'socket'
  25.  
  26. MULTICAST_ADDR = "225.4.5.7"
  27. PORT= 28960
  28.  
  29. begin
  30. socket = UDPSocket.open
  31. socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_TTL, [1].pack('i'))
  32. socket.send(ARGV.join(' '), 0, MULTICAST_ADDR, PORT)
  33. ensure
  34. socket.close
  35. end
Add Comment
Please, Sign In to add comment