1Protocol::WebSocket::ClUiseenrt(C3opnmt)ributed Perl DocPurmoetnotcaotli:o:nWebSocket::Client(3pm)
2
3
4

NAME

6       Protocol::WebSocket::Client - WebSocket client
7

SYNOPSIS

9           my $sock = ...get non-blocking socket...;
10
11           my $client = Protocol::WebSocket->new(url => 'ws://localhost:3000');
12           $client->on(
13               write => sub {
14                   my $client = shift;
15                   my ($buf) = @_;
16
17                   syswrite $sock, $buf;
18               }
19           );
20           $client->on(
21               read => sub {
22                   my $client = shift;
23                   my ($buf) = @_;
24
25                   ...do smth with read data...
26               }
27           );
28
29           # Sends a correct handshake header
30           $client->connect;
31
32           # Register on connect handler
33           $client->on(
34               connect => sub {
35                   $client->write('hi there');
36               }
37           );
38
39           # Parses incoming data and on every frame calls on_read
40           $client->read(...data from socket...);
41
42           # Sends correct close header
43           $client->disconnect;
44

DESCRIPTION

46       Protocol::WebSocket::Client is a convenient class for writing a
47       WebSocket client.
48
49
50
51perl v5.34.0                      2022-01-21  Protocol::WebSocket::Client(3pm)
Impressum