server.rb (run first, in one window)
require 'socket'
BasicSocket.do_not_reverse_lookup = true
# Create socket and bind to address
client = UDPSocket.new
client.bind('0.0.0.0', 33333)
data, addr = client.recvfrom(1024) # if this number is too low it will drop the larger packets and never give them to you
puts "From addr: '%s', msg: '%s'" % [addr.join(','), data]
client.close
client.rb (run in another window
require 'socket'
sock = UDPSocket.new
data = 'I sent this'
sock.send(data, 0, '127.0.0.1', 33333)
sock.close
related:
http://betterlogic.com/roger/?p=1646