NAME
Protocol::WebSocket::Fast::ClientParser - Client-side websocket parser
SYNOPSIS
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) {
# ...
}
DESCRIPTION
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.
METHODS
new([\%params])
Creates new instance of parser. See Parser's configure()
method for parameters description.
connect_request($request)
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.
$request
should be a Protocol::WebSocket::Fast::ConnectRequest object or a params hashref that its constructor supports.
my $data = $parser->connect_request($request);
# send $data to network
connect($data)
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);
SEE ALSO
Protocol::WebSocket::Fast::ConnectRequest
Protocol::WebSocket::Fast::ConnectResponse