NAME

Net::WebSocket::Frame::close

SYNOPSIS

my $frm = Net::WebSocket::Frame::close->new(

    #Optional, can be either empty (default) or four random bytes
    mask => q<>,

    code => 'SUCCESS',      #See below

    reason => 'yeah, baby', #See below
);

$frm->get_type();           #"close"

$frm->is_control_frame();   #1

my $mask = $frm->get_mask_bytes();

my ($code, $reason) = $frm->get_code_and_reason();

#If, for some reason, you need the raw payload:
my $payload = $frm->get_payload();

my $serialized = $frm->to_bytes();

Note that, as per RFC 6455, close messages can have any of:

  • no code, and no reason

  • a code, and no reason

  • a code, and a reason that cannot exceed 123 bytes

The code (i.e., $code) is subject to the limitations that RFC 6445 describes. You can also, in lieu of a numeric constant, use the following string constants that Microsoft defines:

  • SUCCESS (1000)

  • ENDPOINT_UNAVAILABLE (1001)

  • PROTOCOL_ERROR (1002)

  • INVALID_DATA_TYPE (1003)

  • INVALID_PAYLOAD (1007)

  • POLICY_VIOLATION (1008)

  • MESSAGE_TOO_BIG (1009)

  • UNSUPPORTED_EXTENSIONS (1010)

  • SERVER_ERROR (1011)

    NOTE: As per erratum 3227, this status is meant to encompass client errors as well. Since these constants are meant to match Microsoft’s (in default of such in the actual WebSocket standard), however, Net::WebSocket only recognizes SERVER_ERROR as an alias of 1011. Hopefully a future update to the WebSocket standard will include useful string aliases for the status codes.

    Also note that the official list of status codes contains some that don’t have string constants.