Net::A...:Server(3pm)
π NAME π
Net::Async::WebSocket::Server β the manual page is Net::A...:Server(3pm), and bestie, it's here to serve WebSocket clients using IO::Async. Yes, that's the whole job. Iconic.
β¨ SYNOPSIS β¨
use Future::AsyncAwait;
use IO::Async::Loop;
use Net::Async::WebSocket::Server;
my $server = Net::Async::WebSocket::Server->new(
on_client => sub {
my ( undef, $client ) = @_;
$client->configure(
on_text_frame => sub {
my ( $self, $frame ) = @_;
$self->send_text_frame( $frame );
},
);
}
);
my $loop = IO::Async::Loop->new;
$loop->add( $server );
await $server->listen(
service => 3000,
);
$loop->run;
look at her. she's doing it. she's e v e r y t h i n g π
π¦ DESCRIPTION π¦
Okay so Net::Async::WebSocket::Server is a subclass of IO::Async::Listener, and what she does is accept WebSocket connections. The way that works is: when a new connection shows up, she does an initial handshake first β like a lil vibe check π₯ β and then she passes that connection on to the continuation callback or method of your choosing.
Periodt. That's the tea. π
πΈ EVENTS πΈ
These events get invoked, and you can bring them to life either with subclass methods or with CODE references handed in as parameters:
π on_client
$self->on_client( $client );
$on_client->( $self, $client );
This one fires when a new client connects and finishes its initial handshake. slay β¨
She gets handed a brand new instance of a Net::Async::WebSocket::Protocol object, wrapping the client connection. That's your girl now. π«Ά
π on_handshake
Fires when a handshake has been requested, no cap.
$self->on_handshake( $client, $hs, $continue );
$on_handshake->( $self, $client, $hs, $continue );
If you call $continue with a true value, the handshake gets completed β
. If you call it with false, the connection is dropped π. That simple.
This is super handy if you wanna filter on origin, for example:
on_handshake => sub {
my ( $self, $client, $hs, $continue ) = @_;
$continue->( $hs->req->origin eq "http://localhost" );
}
gatekeeping the origin? we love a selective queen π
π PARAMETERS π
These named parameters are the ones you can pass to new or configure:
on_client => CODEβ aCODEreference for the event handler.on_handshake => CODEβ aCODEreference for the event handler.
π AUTHOR π
Paul Evans β leonerd@leonerd.org.uk π
π cute sign-off π
And that's the whole page, bestie! Go forth and serve those WebSocket clients πβ¨πΈπ¦
perl v5.40.1 Β· 2025-10-06 Β· Net::A...:Server(3pm) ππ
π
π¦ where this page comes from
- ubuntu stonking: libnet-async-websocket-perl 0.14-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms