Skip to content

Instantly share code, notes, and snippets.

@ippa
Created November 26, 2010 15:18
Show Gist options
  • Save ippa/716831 to your computer and use it in GitHub Desktop.
Save ippa/716831 to your computer and use it in GitHub Desktop.
# client
@ip = "127.0.0.1"
@socket = UDPSocket.new
@socket.connect(@ip, SERVER_PORT)
def send_to_server(data = {})
packed = Marshal.dump(data)
@socket.send(packed, 0)
end
send_to_server(:x => 10, :foo => "bar")
# server
socket = UDPSocket.open
socket.bind('', SERVER_PORT)
p "* Server initiated"
loop do
begin
data, info = socket.recvfrom(1024)
object = Marshal.load(data)
rescue
puts "Error reading and unpacking data: #{$!}"
end
protocol, port, ip, ip2 = info
socket.send("PIXEL/ACK", 0, ip, CLIENT_PORT)
p data.length
p info
p object
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment