NAME
Reflex::Client - A non-blocking socket client.
VERSION
version 0.056
SYNOPSIS
This is a complete working TCP echo client. It's the version of eg/eg-35-tcp-client.pl available at the time of this writing.
use lib qw(../lib);
{
package TcpEchoClient;
use Moose;
extends 'Reflex::Client';
sub on_client_connected {
my ($self, $args) = @_;
$self->connection()->put("Hello, world!\n");
};
sub on_client_data {
my ($self, $args) = @_;
# Not chomped.
warn "got from server: $args->{data}";
# Disconnect after we receive the echo.
$self->stop();
}
}
TcpEchoClient->new(
remote_addr => '127.0.0.1',
remote_port => 12345,
)->run_all();
DESCRIPTION
Reflex::Client is scheduled for substantial changes. One of its base classes, Reflex::Handle, will be deprecated in favor of Reflex::Role::Readable and Reflex::Role::Writable. Hopefully Reflex::Client's interfaces won't change much as a result, but there are no guarantees. Your ideas and feedback for Reflex::Client's future implementation are welcome.
Reflex::Client is a high-level base class for non-blocking socket clients. As with other Reflex::Base classes, this one may be subclassed, composed with "has", or driven inline with promises.
Attributes
Reflex::Client extends (and includes the attributes of) Reflex::Connector, which extends Reflex::Handle. It also provides its own attributes.
protocol
The "protocol" attribute contains the name of a class that will handle I/O for the client. It contains "Reflex::Stream" by default.
Protocol classes should extend Reflex::Stream or at least follow its interface.
Public Methods
Reflex::Client extends Reflex::Handle, but it currently provides no additional methods.
Events
Reflex::Client emits some of its own high-level events based on its components' activities.
connected
Reflex::Client emits "connected" to notify consumers when the client has connected, and it's safe to begin sending data.
data
Reflex::Client emits stream data with the "data" event. This event is provided by Reflex::Stream. Please see "data" in Reflex::Stream for the most current documentation.
EXAMPLES
eg/eg-35-tcp-client.pl subclasses Reflex::Client as TcpEchoClient.
SEE ALSO
"ACKNOWLEDGEMENTS" in Reflex "ASSISTANCE" in Reflex "AUTHORS" in Reflex "BUGS" in Reflex "BUGS" in Reflex "CONTRIBUTORS" in Reflex "COPYRIGHT" in Reflex "LICENSE" in Reflex "TODO" in Reflex