Protocol::WebSocket::Fast::ClientParser - Client-side websocket parser
use Protocol::WebSocket::Fast; my $client = Protocol::WebSocket::Fast::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::Fast::Parser.
Methods of this class are used for establishing a logical websocket connection with server.
See Protocol::WebSocket::Fast::Parser for API after establishing a connection.
Creates new instance of parser. See Parser's configure() method for parameters description.
configure()
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::Fast::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::Fast::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::Fast
Protocol::WebSocket::Fast::ConnectRequest
Protocol::WebSocket::Fast::ConnectResponse
Protocol::WebSocket::Fast::Parser
Protocol::WebSocket::Fast::ServerParser
To install Protocol::WebSocket::Fast, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Protocol::WebSocket::Fast
CPAN shell
perl -MCPAN -e shell install Protocol::WebSocket::Fast
For more information on module installation, please visit the detailed CPAN module installation guide.