Protocol::WebSocket::Handshake::Server - WebSocket Server Handshake
my $h = Protocol::WebSocket::Handshake::Server->new; # Parse client request $h->parse(<<"EOF"); 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 EOF $h->error; # Check if there were any errors $h->is_done; # Returns 1 # Create response $h->to_string; # 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
Construct or parse a server WebSocket handshake. This module is written for convenience, since using request and response directly requires the same code again and again.
new
Create a new Protocol::WebSocket::Handshake::Server instance.
new_from_psgi
my $env = { HTTP_HOST => 'example.com', HTTP_CONNECTION => 'Upgrade', ... }; my $handshake = Protocol::WebSocket::Handshake::Server->new_from_psgi($env);
Create a new Protocol::WebSocket::Handshake::Server instance from PSGI environment.
parse
$handshake->parse($buffer); $handshake->parse($handle);
Parse a WebSocket client request. Returns undef and sets error attribute on error.
undef
error
When buffer is passed it's modified (unless readonly).
to_string
Construct a WebSocket server response.
is_done
Check whether handshake is done.
To install Protocol::WebSocket, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Protocol::WebSocket
CPAN shell
perl -MCPAN -e shell install Protocol::WebSocket
For more information on module installation, please visit the detailed CPAN module installation guide.