NAME
XAS::Lib::Net::POE::Client - An asynchronous network client based on POE
SYNOPSIS
This module is a class used to create network clients.
package Client;
use POE;
use XAS::Class
version => '1.0',
base => 'XAS::Lib::Net::POE::Client'
;
sub handle_connection {
my ($self) = $_[OBJECT];
my $packet = "hello!";
$poe_kernel->yield('write_data', $packet);
}
DESCRIPTION
This module handles the nitty-gritty details of setting up the communications channel to a server. You will need to sub-class this module with your own for it to be useful.
An attempt to maintain that channel will be made when/if that server should happen to disappear off the network. There is nothing more unpleasant then having to go around to dozens of servers and restarting processes.
The following methods are responding to POE events and use the POE argument passing conventions.
METHODS
new
This method initializes the class and starts a session to handle the communications channel. It takes the following parameters:
- -alias
-
The session alias, defaults to 'client'.
- -host
-
The servers host name, defaults to 'localhost'.
- -port
-
The servers port number.
- -retry_count
-
Wither to attempt reconnections after they run out. Defaults to true.
- -tcp_keepalive
-
For those pesky firewalls, defaults to false.
read_data(OBJECT, ARG0)
This event is triggered when data is received for the server. It accepts these parameters:
- OBJECT
-
The current class object.
- ARG0
-
The data that has been read.
write_data(OBJECT, ARG0)
You use this event to send data to the server. It accepts these parameters:
- OBJECT
-
The current class object.
- ARGO
-
The data to write out.
handle_connection(OBJECT)
This event is triggered upon initial connection to the server. It accepts these parameters:
- OBJECT
-
The current class object.
connection_down(OBJECT)
This event is triggered to allow you to be notified if the connection to the server is currently down. It accepts these parameters:
- OBJECT
-
The current class object.
connection_up(OBJECT)
This event is triggered to allow you to be notified when the connection to the server is restored. It accepts these parameters:
- OBJECT
-
The current class object.
VARIABLES
The following class variables are available if you want to adjust them.
- ERRORS
-
An array of POSIX error codes.
- RECONNECTIONS
-
An array of seconds to wait for the next reconnect attempt.
SEE ALSO
AUTHOR
Kevin L. Esteb, <kevin@kesteb.us>
COPYRIGHT AND LICENSE
Copyright (C) 2014 Kevin L. Esteb
This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license at http://www.perlfoundation.org/artistic_license_2_0.