Net::A...rotocol(3pm)
π Net::Async::WebSocket::Protocol π
okay so bestie, welcome to Net::Async::WebSocket::Protocol β it lives in the User Contributed Perl Documentation section of your friendly neighbourhood perl man pages, and it is literally here to send and receive WebSocket frames. it's giving "the handshake already happened, we're just vibing now" energy fr fr. β¨
πΈ NAME πΈ
Net::Async::WebSocket::Protocol β send and receive WebSocket frames. that's it, that's the whole job, and she does it beautifully. π
β¨ DESCRIPTION β¨
So this class is a subclass of IO::Async::Stream, and what it does is represent an established WebSocket connection β like, one that has already finished its setup handshaking and is now fully ready to pass frames back and forth. no cap. π¦
real talk: you would not normally construct objects of this type directly. like, ever. it's not the move.
For WebSocket clients, go look at Net::Async::WebSocket::Client β that one is a subclass of this class. π«Ά
For WebSocket servers, go look at Net::Async::WebSocket::Server β that one constructs objects in this class when it accepts a new connection, and then passes them along to its event handler. she's the main character behind the scenes, iykyk. π
π EVENTS π
The following events get invoked, either using subclass methods or CODE references in parameters. pick your fighter, both work π
π on_text_frame
$self->on_text_frame( $text );
$on_text_frame->( $self, $text );
Invoked when a text frame is received. It gets passed a Unicode character string that was formed by decoding the received UTF-8 bytes. cute, decoded, ready to read. β¨
π on_frame
$self->on_frame( $text );
$on_frame->( $self, $text );
A synonym for on_text_frame, provided for backward compatibility. she's the older sister, still valid, still loved.
β οΈ okay lowkey important: this may be removed in a later version. so maybe don't build your whole personality around her. π
π on_binary_frame, on_ping_frame, on_pong_frame, on_close_frame
$self->on_..._frame( $bytes );
$on_..._frame->( $self, $bytes );
Invoked when other types of frame are received. These get passed plain byte strings β no decoding, no drama, just raw bytes. π
π on_raw_frame
$self->on_raw_frame( $frame, $bytes );
$on_raw_frame->( $self, $frame, $bytes );
Invoked when a frame is received that does not have a specific handler defined of one of the above types. $frame will be an instance of Protocol::WebSocket::Frame. the catch-all queen π
π PARAMETERS π
The following named parameters may be passed to new or configure:
on_frame => CODEon_text_frame => CODEon_binary_frame, on_ping_frame, on_pong_frame, on_close_frame => CODEon_raw_frame => CODE
β CODE references for event handlers. give her the callbacks and she will call them, periodt. π
masked => BOOLβ whether frames constructed and sent by this instance will be masked. yes/no, on/off, masked/unmasked, your call bestie π
π¦ METHODS π¦
The following methods, documented in an await expression, return Future instances. so yes, you await them, and yes, that's iconic. β
π send_frame
await $self->send_frame( @args );
Sends a frame to the peer containing containing the given string. (yes, the original says "containing containing" twice β I am not fixing her grammar, that's the lore, we preserve the lore. π)
The arguments are passed to Protocol::WebSocket::Frame's new method.
π real talk: this method is discouraged in favour of the more specific ones listed below. It's only here for back-compatibility, or for sending new frame types that the specific methods don't recognise. so like, use it if you must, but the specific ones are the moment. π
π send_text_frame
await $self->send_text_frame( $text, %params );
Sends a text frame to the peer. The given string will be treated as a Unicode character string, and sent as UTF-8 encoded bytes. she does the encoding for you, no thoughts required. β¨
Any additional arguments will be passed as parameters to the underlying write in IO::Async::Stream call.
π send_TYPE_frame
await $self->send_binary_frame( $bytes, %params );
await $self->send_ping_frame( $bytes, %params );
await $self->send_pong_frame( $bytes, %params );
await $self->send_close_frame( $bytes, %params );
Sends a frame of the given type to the peer. pick a type, any type, she's got you π
Any additional arguments will be passed as parameters to the underlying write in IO::Async::Stream call.
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk>
okay that's the whole page bestie, you ate it up, go forth and send frames responsibly π«Άπ
signing off β this was perl v5.40.1, dated 2025-10-06, and honestly? iconic of her. periodt. πβ¨
π¦ 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