Net::WebSocket::Handshake::Server
my $hsk = Net::WebSocket::Handshake::Server->new( #optional subprotocols => [ 'echo', 'haha' ], #optional extensions => \@extension_objects, ); $hsk->valid_method_or_die( $http_method ); #optional $hsk->consume_headers(@headers_kv_pairs); my $resp_hdr = $hsk->to_string();
This class implements WebSocket handshake logic for a server. It handles the basics of handshaking and, optionally, subprotocol and extension negotiation.
Returns an instance of this class. %OPTS is as described in the base class; there are no options specific to this class.
Throws an exception if the given PROTOCOL isn’t the HTTP protocol (HTTP/1.1) that WebSocket requires for all requests.
You only need this if if you’re not using a request-parsing interface that’s compatible with HTTP::Request; otherwise, Net::WebSocket::HTTP_R’s handshake_consume_request() function will do this (and other niceties) for you.
handshake_consume_request()
Throws an exception if the given METHOD isn’t the HTTP method (GET) that WebSocket requires for all requests.
As with valid_protocol_or_die(), Net::WebSocket::HTTP_R might call this method for you.
valid_protocol_or_die()
#...Parse the request’s headers yourself... my $hsk = Net::WebSocket::Handshake::Server->new( #base 64, gotten from request key => '..', #optional - same as in non-legacy interface subprotocols => [ 'echo', 'haha' ], #optional, instances of Net::WebSocket::Handshake::Extension extensions => \@extension_objects, ); #Note the need to conclude the header text manually. print $hsk->create_header_text() . "\x0d\x0a";
To install Net::WebSocket, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::WebSocket
CPAN shell
perl -MCPAN -e shell install Net::WebSocket
For more information on module installation, please visit the detailed CPAN module installation guide.