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

AnyEvent and strange DNS queries

by Wiggins (Friar)
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.

http://search.cpan.org/~mlehmann/AnyEvent/lib/AnyEvent/Intro.pod
Implementing simple HTTP and HTTPS GET requests with AnyEvent::Handle

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

09:57:58.171573 IP 10.105.0.201.40128 > xxx.yyy.177.34.53: 18968+ SRV? + _http._tcp.www.google.com. (43) 09:57:58.239373 IP xxx.yyy.177.34.53 > 10.105.0.201.40128: 18968 NXDom +ain 0/1/0 (93) 09:58:03.185482 ARP, Request who-has 10.105.0.1 tell 10.105.0.201, 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 10.105.0.1 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 "www.google.com", "/", 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.

Comment on AnyEvent and strange DNS queries
Select or Download Code
Re: AnyEvent and strange DNS queries
by Plankton (Priest) on Feb 13, 2013 at 03:04 UTC
    From looking and the tcpdump output you posted it looks like the host 10.105.0.201 is making query that is equivalent to this dig command ...
    $ dig _http._tcp.www.google.com. 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.
Re: AnyEvent and strange DNS queries
by zwon (Monsignor) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1018391]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2014-12-27 09:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls