Net::A...:Client(3pm)
π NAME π
Net::Async::WebSocket::Client β bestie, it connects you to a WebSocket server using IO::Async. That's the whole vibe. (The page header calls it Net::A...:Client(3pm), and it lives in the User Contributed Perl Documentation, if you were wondering where you even found this.) π¦
β¨ SYNOPSIS β¨
okay so here's literally the whole thing, copy-paste ready:
use Future::AsyncAwait;
use IO::Async::Loop;
use Net::Async::WebSocket::Client;
my $client = Net::Async::WebSocket::Client->new(
on_text_frame => sub {
my ( $self, $frame ) = @_;
print $frame;
},
);
my $loop = IO::Async::Loop->new;
$loop->add( $client );
await $client->connect( url => "ws://$HOST:$PORT/" );
await $client->send_text_frame( "Hello, world!\n" );
$loop->run;
look at her go. iconic. π
πΈ DESCRIPTION πΈ
So Net::Async::WebSocket::Client is a subclass of Net::Async::WebSocket::Protocol, and what she does is connect to a WebSocket server so you can establish a WebSocket connection and pass frames back and forth. that's it, that's the job. π
π₯ METHODS π₯
the following methods are documented in an await expression and they return Future instances. no cap. β¨
π connect
await $self->connect( %params );
Connect to a WebSocket server. she takes these named parameters:
url => STRINGβ the URL you hand over to the WebSocket handshake. it's also what she uses to infer the host and service name (that's the port number, bestie) if you didn't supply them some other way. π«Άreq => Protocol::WebSocket::Requestβ optional. if you pass it, it gives theProtocol::WebSocket::Requestinstance used for performing the handshake.
The returned Future returns the client instance itself, which makes it super handy for chaining constructors together. the way that works is chefs kiss.
π connect (void)
$self->connect( %params );
when you're not returning a Future, these extra parameters give you continuations instead:
on_connected => CODEβ aCODEreference to invoke when the handshaking is complete.
π¦ connect_handle
await $client->connect_handle( $handle, %params );
Sets the read and write handles to the IO reference you gave her, then performs the initial handshake using the parameters you passed in. those parameters are exactly as for "connect". same energy, different door. β¨
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk>
and that's the whole page, bestie!! go forth and websocket π§
this was perl v5.40.1, dated 2025-10-06, and the page answers to Net::A...:Client(3pm) β mwah, bye ππ
π¦ 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