Sha256: c99b8ef785cafbd24a81b6e67faae382eec7a2f3cd2437929fbdb2c203edce43
Contents?: true
Size: 899 Bytes
Versions: 3
Compression:
Stored size: 899 Bytes
Contents
require 'socket' require 'ipaddr' class UDPTest def listen s = UDPSocket.new # membership = IPAddr.new(multicast_addr).hton + IPAddr.new(bind_addr).hton # s.setsockopt(:IPPROTO_UDP, :IP_ADD_MEMBERSHIP, membership) s.bind('', 3040) while true data, addr = s.recvfrom(1024) puts "addr = #{addr}\r\ndata =" p data end end def start_server multi_addr = '225.1.1.1' bind_addr = '0.0.0.0' sock = UDPSocket.new membership = IPAddr.new(multi_addr).hton + IPAddr.new(bind_addr).hton sock.setsockopt(:IPPROTO_IP, :IP_ADD_MEMBERSHIP, membership) sock.bind(bind_addr, 3040) while true data, addr = sock.recvfrom(2000) # if this number is too low it will drop the larger packets and never give them to you p "From addr: #{addr}, msg: #{data}" p data.unpack('CCna8') puts '' end sock.close end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
prologix_gpib-0.5.3 | test_server.rb |
prologix_gpib-0.5.2 | test_server.rb |
prologix_gpib-0.5.0 | test_server.rb |