NAME
AnyEvent::mDNS - Multicast DNS in AnyEvent style
SYNOPSIS
use AnyEvent::mDNS;
my $cv = AnyEvent->condvar;
AnyEvent::mDNS::discover '_http._tcp', on_timeout => $cv, sub {
my $service = shift;
warn "Found $service->{name} ($service->{proto}) running on $service->{host}:$service->{port}\n";
};
$cv->recv;
DESCRIPTION
AnyEvent::mDNS is a multicast DNS resolver using AnyEvent framework.
METHODS
- discover
-
# receive service as it's found (faster) AnyEvent::mDNS::discover $proto, on_timeout => $cv, $cb->($service_as_found); # receive all services in one shot (but after a timeout) AnyEvent::mDNS::discover $proto, on_timeout => $cv; my @all_services = $cv->recv;
Run multicast DNS query and receive the services discovered with the callback. The callback is passed with the service as a hash reference with keys:
host
,port
,proto
andname
.The UDP socket for the DNS query times out in 3 seconds, and all the services found are passed to the callback you specified with
on_timeout
(after the timeout).Although the timeout is done in a non-blocking way, you might want to retrieve the service as soon as possible, in which case you specify another callback as the last argument, then each service will be passed to the callback as it's found.
You can obviously write your own AnyEvent timer loop to run this mDNS query from time to time with smart interval (See the Multicast DNS Internet Draft for details), to keep the discovered list up-to-date.
AUTHOR
Tatsuhiko Miyagawa <miyagawa@bulknews.net>
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
AnyEvent::DNS http://files.multicastdns.org/draft-cheshire-dnsext-multicastdns.txt