Net::A...:Client(3pm)

πŸ“¦
version 0.14 Β· 3 versions
, in ubuntu stonking

πŸ’– 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 the Protocol::WebSocket::Request instance 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 β€” a CODE reference 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