Mojo::Server::TCP - Generic TCP server
0.01
use Mojo::Server::TCP; my $echo = Mojo::Server::TCP->new(listen => ['tcp//*:9000']); $echo->on(read => sub { my($echo, $id, $chunk, $stream) = @_; $stream->write($chunk); }); $echo->start;
Mojo::Server::TCP is a generic TCP server based on the logic of the Mojo::Server::Daemon.
$self->on(close => sub { my($self, $id) = @_ });
Emitted safely when a new client connects to the server.
Emitted safely if the stream gets closed.
$self->on(error => sub { my($self, $id, $str) = @_ });
$self->on(error => sub { my($self, $id, $chunk, $stream) = @_ });
Emitted safely if new data arrives on the stream.
$self->on(timeout => sub { my($self, $stream) = @_ });
Emitted safely if the stream has been inactive for too long and will get closed automatically.
$str = $daemon->server_class; $self = $self->server_class('Mojo::Server::Prefork');
Used to set a custom server class. The default is Mojo::Server::Daemon. Check out Mojo::Server::Prefork if you want a faster server.
$array_ref = $self->listen; $self = $self->listen(['tcp://localhost:3000']);
List of one or more locations to listen on, defaults to "tcp://*:3000".
$self = $self->run;
Start accepting connections and run the server.
$self = $self->start;
Start listening for connections. See also "run".
$self = $self->stop;
Stop the server.
Jan Henning Thorsen - jhthorsen@cpan.org
jhthorsen@cpan.org
To install Mojo::Server::TCP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Server::TCP
CPAN shell
perl -MCPAN -e shell install Mojo::Server::TCP
For more information on module installation, please visit the detailed CPAN module installation guide.