Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

AnyEvent and strange DNS queries

by Wiggins (Hermit)
on Feb 12, 2013 at 15:28 UTC ( #1018391=perlquestion: print w/replies, xml ) Need Help??
Wiggins has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks; I am looking for an event loop to handle multiple connections, in and out, w/ different protocols. I came across a reference to 'AnyEvent' which I started to evaluate.

I built a program using the 1st HTTP example and some additional prints to track execution.
Implementing simple HTTP and HTTPS GET requests with AnyEvent::Handle

I have listed the code at the end. It is a simple 'GET' to ''. A network trace produces:

09:57:58.171573 IP > xxx.yyy.177.34.53: 18968+ SRV? + (43) 09:57:58.239373 IP xxx.yyy.177.34.53 > 18968 NXDom +ain 0/1/0 (93) 09:58:03.185482 ARP, Request who-has tell, len +gth 28 0x0000: 0001 0800 0604 0001 001e 4c67 1c5f 0a69 ..........Lg +._.i 0x0010: 00c9 0000 0000 0000 0a69 0001 .........i.. 09:58:03.187671 ARP, Reply is-at 00:90:0b:25:0b:71, length +28 0x0000: 0001 0800 0604 0002 0090 0b25 0b71 0a69 ...........% +.q.i 0x0010: 0001 001e 4c67 1c5f 0a69 00c9 ....Lg._.i..
This is the total network activity. Obviously, the code goes no further. That initial query looks 'odd' to say the least (_http._tcp.www...). Can someone explain what AnyEvent::DNS is doing here?

use AnyEvent ; use AnyEvent::Strict ; use AnyEvent::Handle; sub http_get { my ($host, $uri, $cb) = @_; print "http_get: $host, $uri called\n"; ###RPT # store results here #my ($response, $header, $body); my $handle; $handle = new AnyEvent::Handle connect => [$host => 'http'], on_error => sub { print "on_error: condition\n"; ###RPT $cb->("HTTP/1.0 500 $!"); $handle->destroy; # explicitly destroy handle }, on_eof => sub { print "on_eof: condition\n"; ###RPT $cb->($response, $header, $body); $handle->destroy; # explicitly destroy handle }; print "moving to push_write Get\n"; ###RPT $handle->push_write ("GET $uri HTTP/1.0\015\012\015\012"); print "after push_write Get\n"; ###RPT # now fetch response status line $handle->push_read (line => sub { my ($handle, $line) = @_; print "push_read: statusLine <$line>\n"; ###RPT $response = $line; }); # then the headers $handle->push_read (line => "\015\012\015\012", sub { my ($handle, $line) = @_; print "push_read: header <$line>\n"; ###RPT $header = $line; }); # and finally handle any remaining data as body $handle->on_read (sub { $body .= $_[0]->rbuf; print "on_read: body <$line>\n"; ###RPT $_[0]->rbuf = ""; }); } http_get "", "/", sub { # my ($response, $header, $body) = @_; print $response, "\n", $header, "\n", ###RPT $body; };

It is always better to have seen your target for yourself, rather than depend upon someone else's description.

Replies are listed 'Best First'.
Re: AnyEvent and strange DNS queries
by zwon (Abbot) on Feb 13, 2013 at 11:11 UTC
    That's because you are trying to connect to http service:
    my $handle; $handle = new AnyEvent::Handle connect => [$host => 'http'],
    It tries to find the SRV record for http service on $host. Replace it with the port number:
    connect => [$host => 80],
    and it will just resolve the host name.
Re: AnyEvent and strange DNS queries
by Plankton (Vicar) on Feb 13, 2013 at 03:04 UTC
    From looking and the tcpdump output you posted it looks like the host is making query that is equivalent to this dig command ...
    $ dig SRV @xxx.yyy.177.34
    ... which results in a NXDOMAIN meaning the DNS server at xxx.yyy.177.34 doesn't have an answer for the query.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1018391]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2017-02-25 05:08 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (365 votes). Check out past polls.