Skip to content

Instantly share code, notes, and snippets.

@chintanparikh
Created April 14, 2015 03:37
Show Gist options
  • Save chintanparikh/efaa39868ea0b24ecb96 to your computer and use it in GitHub Desktop.
Save chintanparikh/efaa39868ea0b24ecb96 to your computer and use it in GitHub Desktop.
def receive_packet
begin
Timeout.timeout(@timeout) do
packet_string, addr = @udp_socket.recvfrom(@buffer_size)
packet = Packet.from_string(packet_string)
puts "Returning packet"
return packet
# unless packet.corrupted?
# unless packet.is_duplicate?(@expected_seq_number)
# return packet
# else
# puts "Received duplicate packet"
# end
# else
# puts "Corrupted packets"
# end
end
rescue Timeout::Error
return nil
rescue Timeout::ExitException
return nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment