NAME

POE::Class::Server::TCP - Base class to create a POE TCP Server

SYNOPSIS

#!/usr/bin/perl

use strict;


# A simple echo server
package My::EchoServer;

use POE;

use strict;
use base 'POE::Class::Conn::TCPStream';

sub handler_conn_input {
    my ($self, $input) = @_[OBJECT, ARG0];
    return if $self->get_shutdown;
    $self->get_wheel->put($input);
}

package main;

use POE qw/Class::Server::TCP/;

my $server = new POE::Class::Server::TCP(
    port       => 'echo',
    conn_class => 'My::EchoServer',
    alias      => 'echo'
);
# - or -
$server = new POE::Class::Server::TCP;
$server->set_port('echo');
$server->set_conn_class('My::EchoServer');
$server->set_alias('echo');
# - or -
my $server = new POE::Class::Server::TCP;
$server->configure(
    port       => 'echo',
    conn_class => 'My::EchoServer',
    alias      => 'echo'
);

# Creates the session
my $session = $server->start;
printf "Created echo session %d\n", $session->ID;

$poe_kernel->run;

DESCRIPTION

POE::Class::Server::TCP is a base class for creating POE TCP Servers. Through inheritance with other POE::Class:: classes it provides a faily simple subclass interface.

METHODS

new

The constructor. It takes a hash of arguments which correspond to accessor functions of the same name.

start

Creates the and returns a new session specified by set_session_type(), defaults to POE::Session. You should setup the connection information before calling this method as the SocketFactory will be created when this is called. Inherited.

disconnect

Disconnects the server. This does not kill and current connections POE::Class::Conn for that.

connect

This method creates a POE::Wheel::SocketFactory with current object information from get_port(), get_address() and get_domain(). The accessor set_wheel() is called with the new SocketFactory.

create_states

Creates the following object states in the current session: State Handler error - handler_error connection - handler_connection

other methods

POE::Class for a complete list.

ACCESSOR METHODS

set_alias
get_alias

Accessor method for the session alias. If no alias is set when start() is called no alias will be created. Inherited.

set_shutdown
get_shutdown

Accessor method for shutdown. When we are shutdown no more connections will be accepted. This does not mean the session will exit right away. When all connection classes have finished the session will end. Inherited.

set_session_type
get_session_type

Specifies the class used to created the session when start() is called. Defaults to POE::Session.

set_port
get_port

Sets the local port to bind to.

set_address
get_address

Sets the local address to bind to.

set_domain
get_domain

Sets the SocketDomain for SocketFactory.

set_conn_class
get_conn_class

Sets the connection class used when a new connection is accepted. Defaults to POE::Class::Conn::TCPStream. You will want to set this to a subclass of POE::Class::Conn::TCPStream.

set_wheel
get_wheel

Sets the current wheel, usually a POE::Wheel::SocketFactory. This method is called from connect() with a POE::Wheel::SocketFactory.

HANDLERS

handler_start

This handler sets a session alias if one was defined and then Calles connect().

handler_child

Cleans up connections stored via set_connections() and session_id_to_conn().

handler_shutdown

Sets shutdown to true and calles disconnect().

handler_error

Warns with the error and calles disconnect().

handler_connection

Called from POE::Wheel::SocketFactory when a connection is accepted. Creates a new connection object defined by set_conn_class().

TODO

Write better documentation.

AUTHOR

Scott Beck <sbeck@gossamer-threads.com>

SEE ALSO

POE POE::Class POE::Class::Conn POE::Class::Conn::Stream POE::Class::Conn::TCPStream