The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Reflex::Client - A non-blocking socket client.

VERSION

version 0.011

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 a high-level base class for non-blocking socket clients. As with other Reflex::Object classes, this one may be subclassed, composed with "has", or driven with condvar-like syntax.

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

Reflex Reflex::Client

"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