The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Protocol::WebSocket::Handshake::Client - WebSocket Client Handshake

SYNOPSIS

    my $h =
      Protocol::WebSocket::Handshake::Client->new(url => 'ws://example.com');

    # Create request
    $h->to_string; # GET /demo HTTP/1.1
                   # Upgrade: WebSocket
                   # Connection: Upgrade
                   # Host: example.com
                   # Origin: http://example.com
                   # Sec-WebSocket-Key1: 18x 6]8vM;54 *(5:  {   U1]8  z [  8
                   # Sec-WebSocket-Key2: 1_ tx7X d  <  nw  334J702) 7]o}` 0
                   #
                   # Tm[K T2u

    # Parse server response
    $h->parse(<<"EOF");
    HTTP/1.1 101 WebSocket Protocol Handshake
    Upgrade: WebSocket
    Connection: Upgrade
    Sec-WebSocket-Origin: http://example.com
    Sec-WebSocket-Location: ws://example.com/demo

    fQJ,fN/4F4!~K~MH
    EOF

    $h->error;   # Check if there were any errors
    $h->is_done; # Returns 1

DESCRIPTION

Construct or parse a client WebSocket handshake. This module is written for convenience, since using request and response directly requires the same code again and again.

ATTRIBUTES

url

    $handshake->url('ws://example.com/demo');

Set or get WebSocket url.

METHODS

new

Create a new Protocol::WebSocket::Handshake::Client instance.

parse

    $handshake->parse($buffer);

Parse a WebSocket server response. Returns undef and sets error attribute on error. Buffer is modified.

to_string

Construct a WebSocket client request.

is_done

Check whether handshake is done.