AnyEven...xt::Ping(3)
π NAME π
AnyEvent::XMPP::Ext::Ping β literally the implementation of XMPP Ping XEP-0199, bestie. That's it, that's the whole vibe. It lives in the User Contributed Perl Documentation corner of the man-page universe β¨
πΈ SYNOPSIS πΈ
use AnyEvent::XMPP::Ext::Ping;
my $con = AnyEvent::XMPP::IM::Connection->new (...);
$con->add_extension (my $ping = AnyEvent::XMPP::Ext::Ping->new);
# this enables auto-timeout of a connection if it didn't answer
# within 120 seconds to a ping with a reply
$ping->enable_timeout ($con, 120);
my $cl = AnyEvent::XMPP::Client->new (...);
$cl->add_extension (my $ping = AnyEvent::XMPP::Ext::Ping->new);
# this enables auto-timeout of newly created connections
$ping->auto_timeout (120);
$ping->ping ($con, 'ping_dest@server.tld', sub {
my ($time, $error) = @_;
if ($error) {
# we got an error
}
# $time is a float (seconds) of the rtt if you got Time::HiRes
});
No cap, that's the whole program right there π«Ά
π¦ DESCRIPTION π¦
okay so this extension implements XEP-0199: XMPP Ping. It gives you the power to define an automatic ping timeouter that will disconnect dead connections β like, the ones that ghosted you and didn't reply to a ping after N seconds π. See also the docs for the enable_timeout method below, mwah π
It also lets you send pings to literally any XMPP entity you want, and it'll measure how long it took β if you got Time::HiRes. If you don't... it's giving undef energy, we'll get to that π
π METHODS π
β new (%args)
Creates a new ping handle. Fresh ping handle, main character energy π
π₯ auto_timeout ($timeout)
This one enables automatic connection timeout of new connections. It calls enable_timeout (see below, bestie, keep reading π
) for every new connection that was connected and emitted a stream_ready event.
Super useful if you want connections that have this extension to automatically be timeouted. Especially iconic with modules like AnyEvent::XMPP::Client (peep the SYNOPSIS above, it's right there π).
π enable_timeout ($con, $timeout)
This enables a periodical ping on the connection $con. $timeout must be the seconds that the ping intervals last. Periodt β°
If the server connected via $con didn't respond within $timeout seconds, the connection $con will be disconnected. Bye bestie ππ
β οΈ ngl, heads up: there's already a basic timeout mechanism for dead TCP connections inAnyEvent::XMPP::Connectionβ see also thewhitespace_ping_intervalconfiguration variable for a connection there. It then will depend on TCP timeouts to disconnect the connection. So basically the low-key default is already doing stuff.
Use enable_timeout and auto_timeout only if you really feel like you need an explicit timeout for your connections. Like, fr fr, only if you're sure π«Ά
βοΈ ping ($con, $dest, $cb, $timeout)
This method sends a ping request to $dest via the AnyEvent::XMPP::Connection in $con. If $dest is undefined, the ping will be sent to the connected server (sending it to nobody in particular, iconic behaviour honestly). $cb gets called when either the ping timeouts, an error occurs, or the ping result was received. $timeout is an optional timeout for the ping request β if $timeout isn't given, the default IQ timeout for the connection is the relevant timeout. iykyk β¨
The first argument to $cb will be the seconds of the round trip time for that request (if you have Time::HiRes). If you don't have Time::HiRes installed, the first argument will be undef. Sad but true π
The second argument to $cb will be either undef if no error occured, or a AnyEvent::XMPP::Error::IQ error object. π
π§ ignore_pings ($bool)
This method is mostly for testing β it tells this extension to ignore all ping requests and will prevent any response from being sent. Screaming into the void, on purpose π
π AUTHOR π
Robin Redeker, "<elmex at ta-sa.org>", JID: "<elmex at jabber.org>" β the legend themselves π
π COPYRIGHT & LICENSE π
Copyright 2007, 2008 Robin Redeker, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie π perl v5.42.2, dated 2026-02-15 β go forth and ping responsibly, ily, mwah πππ¦
π¦ where this page comes from
- alpine 3.24: perl-anyevent-xmpp-doc 0.55-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms