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

NAME

POE::Component::Server::TCP - simplified TCP server

SYNOPSIS

  use POE;

  sub accept_handler {
    my ($socket, $remote_address, $remote_port) = @_[ARG0, ARG1, ARG2];
    # code goes here to handle the accepted socket
  }

  sub error_handler {
    my ($op, $errnum, $errstr) = @_[ARG0, ARG1, ARG2];
    warn "server encountered $op error $errnum: $errstr";
    # possibly shut down the server
  }

  new POE::Component::Server::TCP
    ( Port     => $bind_port,
      Acceptor => \&accept_handler,
      Error    => \&error_handler,  # Optional.
    );

DESCRIPTION

POE::Component::Server::TCP is a wrapper around POE::Wheel::SocketFactory. It abstracts the steps required to create a TCP server, taking away equal measures of responsibility and control for listening for and accepting remote socket connections.

At version 1.0, the Server::TCP component takes three arguments:

  • Port

    Port is the port the listening socket will be bound to.

  • Acceptor

    Acceptor is a coderef which will be called to handle accepted sockets. The coderef is used as POE::Wheel::SocketFactory's SuccessState, so it accepts the same parameters.

  • Error

    Error is an optional coderef which will be called to handle server socket errors. The coderef is used as POE::Wheel::SocketFactory's FailureState, so it accepts the same parameters. If it is omitted, a fairly standard error handler will be provided. The default handler will log the error to STDERR and shut down the server.

SEE ALSO

POE::Wheel::SocketFactory

BUGS

POE::Component::Server::TCP does not accept many of the options that POE::Wheel::SocketFactory does.

AUTHORS & COPYRIGHTS

POE::Component::Server::TCP is Copyright 2000 by Rocco Caputo. All rights are reserved. POE::Component::Server::TCP is free software, and it may be redistributed and/or modified under the same terms as Perl itself.