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(); #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
Returned as undef (for the code) and an empty string. This diverges from the RFC’s described behavior of returning code 1005.
a code, and no reason
Returned as the code number and an empty string.
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 derive from Microsoft’s WebSocket API:
This appears as
SERVER_ERRORin Microsoft’s documentation; however, erratum 3227 updates the RFC to have this status encompass client errors as well.
Net::WebSocket recognizes either string, but its parsing logic will return only
The following additional status constants derive from the official registry of status codes and are newer than either RFC 6455 or Microsoft’s API:
It is hoped that a future update to the WebSocket specification can include these or similar constant names.