Scroll to navigation

Protocol::WebSocket::Client(3pm) User Contributed Perl Documentation Protocol::WebSocket::Client(3pm)

NAME

Protocol::WebSocket::Client - WebSocket client

SYNOPSIS

    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;

DESCRIPTION

Protocol::WebSocket::Client is a convenient class for writing a WebSocket client.

2019-03-13 perl v5.40.0