Protocol::WebSocket::Fast::ServerParser - Server-side websocket parser
use Protocol::WebSocket::Fast; my $server = Protocol::WebSocket::Fast::ServerParser->new; my $request = $server->accept($data); my $response_data = $request->error ? $server->accept_error : $server->accept_response; # send $response_data to client $server->accept_parsed; $server->accepted;
Server-side specialization of Protocol::WebSocket::Fast::Parser.
Methods of this class are used for accepting a logical websocket connection from client.
See Protocol::WebSocket::Fast::Parser for API after accepting a connection.
Creates new instance of parser. See Parser's configure() method for parameters description.
configure()
Returns true if server finished parsing client's connect request.
Returns true if accept_parsed() and no errors have been met.
accept_parsed()
Parses client's connect request (HTTP-request).
Returns undef if more data is needed, otherwise returns Protocol::WebSocket::Fast::ConnectRequest object. In internal state sets flags whether the requests has been parsed and accepted.
Developer might inspect the request object and add application-specific checks.
In case of any errors, $request->error() will be set.
my $request = $server_parser->accept($data);
Returns serialized successful response from server to client.
Extensions-related headers are automatically added for the build-in extensions, which where enabled by configuration (Protocol::WebSocket::Fast::Parser::configure) if request contained acceptable extension configurations.
Developer might supply customized $response with predefined headers, custom extensions, etc...
$response
$response may be an Protocol::WebSocket::Fast::ConnectResponse object or a params hashref that its constructor supports.
my $data = $server->accept_response({ body => 'hello', headers => {hello => 'world'}, });
Returns serialized failure response from server to client. Further communication with server is not possible, as websocket connection was not established.
Developer might supply customized $object with predefined headers, etc...
$object
$response may be a Protocol::HTTP::Response object or a params hashref that its constructor supports.
my $data = $server->accept_error({ code => 401, body => 'we are unable to process your request because ...', });
Protocol::WebSocket::Fast
Protocol::WebSocket::Fast::ClientParser
Protocol::WebSocket::Fast::ConnectRequest
Protocol::WebSocket::Fast::ConnectResponse
Protocol::WebSocket::Fast::Parser
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.