| AnyEvent::Connection(3pm) | User Contributed Perl Documentation | AnyEvent::Connection(3pm) |
AnyEvent::Connection - Base class for tcp connectful clients
package MyTCPClient;
use base 'AnyEvent::Connection';
package main;
my $client = MyTCPClient->new(
host => 'localhost',
port => 12345,
);
$client->reg_cb(
connected => sub {
my ($client,$connection,$host,$port) = @_;
# ...
$client->after(
$interval, sub {
# Called after interval, if connection still alive
}
);
}
connfail = sub {
my ($client,$reason) = @_;
# ...
},
disconnect => sub {
my ($client,$reason) = @_;
},
error => sub {
my ($client,$error) = @_;
# Called in error conditions for callbackless methods
},
);
$client->connect;
Will be destroyed if connection is destroyed, so no timer invocation after connection destruction.
Will be destroyed if connection is destroyed, so no timer invocation after connection destruction.
my $count;
$client->periodic(1,sub {
$client->periodic_stop if ++$count > 10;
});
# callback will be called only 10 times;
When connected, there are some methods, that proxied to raw connection or to AE::Handle
For next methods there is a feature. Callback will be called in any way, either by successful processing or by error or object destruction
$fh->push_read(chunk => $bytes, $cb->());
$fh->push_write($data);
$fh->push_read(line => $cb->());
Mons Anderson, "<mons at cpan.org>"
Please report any bugs or feature requests to "bug-anyevent-connection at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=AnyEvent-Connection>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc AnyEvent::Connection
You can also look for information at:
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=AnyEvent-Connection>
<http://annocpan.org/dist/AnyEvent-Connection>
<http://cpanratings.perl.org/d/AnyEvent-Connection>
<http://search.cpan.org/dist/AnyEvent-Connection/>
Copyright 2009 Mons Anderson, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 2022-06-05 | perl v5.34.0 |