in reply to Re: AnyEvent::Handle::UDP -- can't get it to receive?
in thread AnyEvent::Handle::UDP -- can't get it to receive?

Dude!
$cv_send->recv;

I've actually got a fair amount of AnyEvent experience, and I totally missed this. You are my new best friend.

Wait, you say you've never done anything with either sockets or AnyEvent before? Quick learner. Anyway, would you mind PM'ing me with your email; if you're bored at work again I might have some PayPal-able learning for you...

Eric.

Replies are listed 'Best First'.
Re^3: AnyEvent::Handle::UDP -- can't get it to receive?
by creeble (Sexton) on Apr 27, 2012 at 00:21 UTC
    Ug, yeah, whoops, that was me (creeble). Forgot to log in.
      Hmmno thanks. I already have a job, and though it has its ups and downs, I'm not looking for another :).
      You're still free to keep asking questions to the monks in general though.

      Edit: Cleaned up code and perltidy'd it. There seems to be a bug in Net::DNS::Packet where, if you remove the debug-flag when creating a new packet object from raw data, the answer section doesn't get decoded.
      use strict; use warnings; use AnyEvent::Handle::UDP; use Socket; use Net::DNS::Packet; use Data::Dump; my $target_host = shift; if (!defined $target_host) { print ("Usage: $0 hostname\n"); exit 1; } my $d = Net::DNS::Packet->new($target_host, "PTR"); my $cv_recv = AnyEvent->condvar; my $t = AnyEvent::Handle::UDP->new( timeout => 3, on_timeout => sub { print STDERR "Nothing happened within the specified timeout ti +meframe...\n"; }, on_error => sub { print STDERR "An error has occurred:"; Data::Dump::dd(@_); }, on_recv => sub { my ($buf, $handle) = @_; my ($res, $err) = Net::DNS::Packet->new(\$buf,1); if ($err) { print STDERR $err . "\n"; } else { Data::Dump::dd($res); } $cv_recv->send; }, ); $t->bind_to(['0.0.0.0', 0]); my $cv_send = $t->push_send($d->data, pack_sockaddr_in(53, Socket::ine +t_aton('IP_OF_DNS-SERVER_HERE'))); print ("Waiting for data to be sent..."); $cv_send->recv; print ("[OK]\n"); print ("Waiting for data to arrive..."); $cv_recv->recv; print ("[OK]\n");