WebSocket::Message - Common Class for Request and Response
use WebSocket::Request; my $req = WebSocket::Request->new( host => 'example.com', uri => '/demo' protocol => 'com.example.chat', ) || die( WebSocket::Request->error, "\n" );
v0.1.0
This is a common class for WebSocket::Request and WebSocket::Response
Sets or gets the buffer. It returns a scalar object
Sets or gets the challenge returned to the client.
Sets or gets the checksum. If a checksum is provided, it returns the current object.
If no checksum is provided, it will compute one based on the value of "number1", "number2" and "challenge". It returns the checksum as a regular string.
Alias for "buffer"
Set or get the available extensions. For example permessage-deflate to enable message compression.
permessage-deflate
You can set this to either a string or a WebSocket::Extension object if you want, for example to set the extension parameters.
See rfc6455 section 9.1 for more information on extension.
If an argument is provided, it takes either an WebSocket::Headers object, or an object that inherits from HTTP::Headers, or an array reference.
It returns a WebSocket::Headers and will instantiate a WebSocket::Headers object if one is not already set.
Returns the WebSocket::Headers as a string by calling "as_string" in WebSocket::Headers
Sets or gets the header value for Host
Host
Returns true if the error code provided is a client error.
Returns true when the parsing is done.
Returns true when the provided code is an error
Returns true when the provided code is a redirect, which under the WebSocket is possible during the handshake only.
Returns true when the provided code is a server error.
Returns true when the provided code is a success
Sets or gets the maximum message size as an integer.
This is a default method to store a number used for the checksum challenge sent to the client.
This method is overriden by WebSocket::Request or WebSocket::Response
Provided with some chunk data, and this will parse it and return a status. See "CONSTANTS" below.
Once parsing is done, you can retrieve the relevant object with "request" which returns a WebSocket::Request object or "response" which returns a WebSocket::Response object.
If an error occurs, this will returns undef and sets an error exception
undef
Returns the http protocol used, which should always be HTTP/1.1
HTTP/1.1
Set or get a WebSocket::Request object. This is set by "parse_chunk"
Set or get a WebSocket::Response object. This is set by "parse_chunk"
Boolean value. True when the connection is using ssl, false otherwise.
Returns the status message provided by the other party.
Set or get an array object of WebSocket protocols.
Returns a Module::Generic::Array object.
See rfc6455 for more information
Set or get the uri of the current request or response. Returns a URI object.
Set or get the WebSocket version supported.
Provided with some data, or a IO::Socket object, and this will add the data to the current buffer (buffer), or issue a read call on the IO::Socket object and read "max_message_size" bytes of data.
read
If the resulting buffer exceeds "max_message_size", this will return undef and sets an error object, so you need to check that the size of the current buffer + the data you provide doe snot exceed the value of "max_message_size"
Provided with some value and this will extract any digit, count the number of spaces and return an integer of the number extracted divided by the number of spaces found.
This is called by the methods "number1" and "number2"
The following constants are available and can be exported into your name space either individually, or by using the tag :all
:all
Returned by "parse_chunk" when the parsing is done.
Returned by "parse_chunk" when the parsing is incomplete.
Returned by "parse_chunk" when the parsing is ongoing and the double line end of header separator has not yet been reached.
Returned by "parse_chunk" to indicate that maybe more data is expected.
Credits to David Robins for code borrowed from HTTP::Parser for chunk parsing
Jacques Deguest <jack@deguest.jp>
WebSocket::Request, WebSocket::Response, HTTP::Headers, HTTP::Parser
Copyright(c) 2021-2023 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.
To install WebSocket, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WebSocket
CPAN shell
perl -MCPAN -e shell install WebSocket
For more information on module installation, please visit the detailed CPAN module installation guide.