NAME
LightTCP::Server - A configurable TCP server with HTTP, CGI, and threading support (Pure Perl OOP)
SYNOPSIS
use LightTCP::Server;
# Basic OOP usage
my $server = LightTCP::Server->new(
server_addr => '0.0.0.0:8080',
server_name => 'MyServer',
verbose => 1,
);
$server->start();
# With custom request handler
my $server = LightTCP::Server->new(
server_addr => '127.0.0.1:8881',
server_type => 'thread',
max_threads => 5,
func_perl => sub {
my ($self, $client, $preq) = @_;
print $client "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nHello!";
return (200, 6);
},
);
$server->start();
DESCRIPTION
LightTCP::Server is a Perl module that implements a flexible TCP server using pure Perl OOP. It handles HTTP requests, serves static files, executes CGI scripts, and supports custom logic via callbacks. Features single-threaded, forked, or threaded operation.
ATTRIBUTES
server_addr(default: '0.0.0.0:8881')-
IP address and port to listen on.
server_type(default: 'single')-
Execution mode:
'single','fork', or'thread'. max_threads(default: 10)-
Maximum concurrent threads for threaded mode.
verbose(default: 0)-
Verbosity level 0-3.
server_auth(default: 0)-
Enable authentication.
server_keys-
Arrayref of valid authentication keys.
func_perl-
Coderef for custom request handling.
METHODS
new(%config)-
Create a new server instance.
start()-
Start the server and block until shutdown.
stop()-
Stop the server gracefully.
logit($msg, $lvl)-
Log a message at the given level.
is_running()-
Returns true if server is running.
validate_config(\%config)-
Class method to validate configuration. Returns undef on success, error message on failure.
EXAMPLES
See "demo.pl" in examples for a complete example.
DATE
Last updated: January 2026