Protoc...:Client(3pm)
π NAME π
Okay bestie, gather round: this page is about Protocol::WebSocket::Client β a WebSocket client. π¦ It lives in the User Contributed Perl Documentation section, and yes, the vibes are immaculate.
πΈ SYNOPSIS πΈ
Here's the code, bestie β copy it exactly, because every line is doing something. The way this synopsis sets up a non-blocking socket, wires handlers, connects, reads, and disconnects? Iconic. π
my $sock = ...get non-blocking socket...;
my $client = Protocol::WebSocket->new(url => 'ws://localhost:3000');
$client->on(
write => sub {
my $client = shift;
my ($buf) = @_;
syswrite $sock, $buf;
}
);
$client->on(
read => sub {
my $client = shift;
my ($buf) = @_;
...do smth with read data...
}
);
# Sends a correct handshake header
$client->connect;
# Register on connect handler
$client->on(
connect => sub {
$client->write('hi there');
}
);
# Parses incoming data and on every frame calls on_read
$client->read(...data from socket...);
# Sends correct close header
$client->disconnect;
Quick vibe check on what just happened: the write handler gets called with the buffer, the read handler gets called with the buffer, connect sends a correct handshake header, read parses incoming data and on every frame calls on_read, and disconnect sends a correct close header. The comments in the code are literally carrying the lore. πβ¨
π DESCRIPTION π
Protocol::WebSocket::Client is a convenient class for writing a WebSocket client. That's it. That's the tea. β It's giving convenience class, and it's literally built for writing a WebSocket client. Periodt. π
Catch you later, bestie! This page is from perl v5.42.0, dated 2019-03-13, and it signs off as Protoc...:Client(3pm). Byeeee π«Άβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Protocol-WebSocket 0.26-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms