Protocol::WebSocket::XS::ClientParser - Client-side websocket parser
use Protocol::WebSocket::XS; my $client = Protocol::WebSocket::XS::ClientParser->new; # create request to be sent via network to server my $req_str = $client->connect_request({ uri => "ws://example.com/", ws_key => "dGhlIHNhbXBsZSBub25jZQ==", ws_protocol => "chat", ws_extensions => [ [ 'permessage-deflate'] ], headers => { 'Origin' => 'http://www.crazypanda.ru', 'User-Agent' => 'My-UA', }, }); # receive server-reply from network my $reply = ''; # establish connection and finish negotiation phase my $response = $client->connect($reply); if ($client->established) { # ... }
Client-side specialization of Protocol::WebSocket::XS::Parser.
Methods of this class are used for establishing a logical websocket connection with server.
See Protocol::WebSocket::XS::Parser for API after establishing a connection.
Creates new instance of parser
Returns serialized HTTP-request that must be sent to server, with all supported extensions preconfigured (see Parser). Extensions-related headers (per-message deflate, etc...) are automatically added.
per-message deflate
$request should be a Protocol::WebSocket::XS::ConnectRequest object or a params hashref that its constructor supports.
$request
my $data = $parser->connect_request($request); # send $data to network
Parses server HTTP-response to the initial HTTP-request. All supported extensions will be enabled in the parser for furher usage, if server agrees to use them.
Returns undef if more data is needed, otherwise returns Protocol::WebSocket::XS::ConnectResponse which can be ignored if you don't care (just check $parser->established()).
If any error occurs during parsing, $response->error() will be set to appropriate constant.
# receive $data my $response = $parser->connect($data);
Protocol::WebSocket::XS
Protocol::WebSocket::XS::ConnectRequest
Protocol::WebSocket::XS::ConnectResponse
Protocol::WebSocket::XS::Parser
Protocol::WebSocket::XS::ServerParser
To install Protocol::WebSocket::XS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Protocol::WebSocket::XS
CPAN shell
perl -MCPAN -e shell install Protocol::WebSocket::XS
For more information on module installation, please visit the detailed CPAN module installation guide.