Mojo::IOLoop::Server - Non-blocking TCP server
use Mojo::IOLoop::Server; # Create listen socket my $server = Mojo::IOLoop::Server->new; $server->on(accept => sub { my ($server, $handle) = @_; ... }); $server->listen(port => 3000); # Start and stop accepting connections $server->start; $server->stop; # Start reactor if necessary $server->reactor->start unless $server->reactor->is_running;
Mojo::IOLoop::Server accepts TCP connections for Mojo::IOLoop.
Mojo::IOLoop::Server inherits all events from Mojo::EventEmitter and can emit the following new ones.
$server->on(accept => sub { my ($server, $handle) = @_; ... });
Emitted safely for each accepted connection.
Mojo::IOLoop::Server implements the following attributes.
my $multi = $server->multi_accept; $server = $server->multi_accept(100);
Number of connections to accept at once, defaults to 50.
50
my $reactor = $server->reactor; $server = $server->reactor(Mojo::Reactor::Poll->new);
Low level event reactor, defaults to the reactor attribute value of the global Mojo::IOLoop singleton.
reactor
Mojo::IOLoop::Server inherits all methods from Mojo::EventEmitter and implements the following new ones.
$server->listen(port => 3000);
Create a new listen socket. Note that TLS support depends on IO::Socket::SSL (1.75+) and IPv6 support on IO::Socket::IP (0.16+).
These options are currently available:
Local address to listen on, defaults to all.
Maximum backlog size, defaults to SOMAXCONN.
SOMAXCONN
Port to listen on.
Enable TLS.
Path to TLS certificate authority file.
Path to the TLS cert file, defaults to a built-in test certificate.
Path to the TLS key file, defaults to a built-in test key.
TLS verification mode, defaults to 0x03.
0x03
my $port = $server->generate_port;
Find a free TCP port, this is a utility function primarily used for tests.
$server->start;
Start accepting connections.
$server->stop;
Stop accepting connections.
Mojolicious, Mojolicious::Guides, http://mojolicio.us.
To install Mojolicious, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious
CPAN shell
perl -MCPAN -e shell install Mojolicious
For more information on module installation, please visit the detailed CPAN module installation guide.