Net::WebSocket::Handshake::Client
my $hsk = Net::WebSocket::Handshake::Client->new( #required uri => 'ws://haha.test', #optional, to imitate a web client origin => .., #optional, base 64 .. auto-created if not given key => '..', #optional subprotocols => [ 'echo', 'haha' ], #optional extensions => \@extension_objects, ); print $hsk->to_string(); $hsk->consume_headers( NAME1 => VALUE1, .. );
This class implements WebSocket handshake logic for a client. It handles the basics of handshaking and, optionally, subprotocol and extension negotiation.
It is a subclass of Net::WebSocket::Handshake.
Returns an instance of the class; %OPTS includes the options from Net::WebSocket::Handshake as well as:
uri - (required) The full URI you’re connecting to.
uri
origin - (optional) The HTTP Origin header’s value. Useful for imitating a web browser.
origin
Throws an exception if the given CODE isn’t the HTTP status code (101) that WebSocket requires in response to all requests. (REASON is included with the exception on error; otherwise it’s unused.)
You only need this if if you’re not using a request-parsing interface that’s compatible with HTTP::Response; otherwise, Net::WebSocket::HTTP_R’s handshake_consume_response() function will do this (and other niceties) for you.
handshake_consume_response()
my $hsk = Net::WebSocket::Handshake::Client->new( #..same as the newer interface, except: #optional extensions => \@extension_objects, ); print $hsk->create_header_text() . "\x0d\x0a"; #...Parse the response’s headers yourself... #Validates the value of the “Sec-WebSocket-Accept” header; #throws Net::WebSocket::X::BadAccept if not. $hsk->validate_accept_or_die($accept_value);
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.