Skip to content

Commit

Permalink
more WebSocket frame examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 9, 2012
1 parent b96e94f commit 2ca4a81
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.78 2012-04-10
- Improved documentation.

2.77 2012-04-09
- Improved Mojo::Transaction::WebSocket to allow custom message parsers.
- Improved help command to be less strict.
Expand Down
37 changes: 26 additions & 11 deletions lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -378,11 +378,11 @@ Emitted when a WebSocket frame has been received.
$ws->unsubscribe('frame');
$ws->on(frame => sub {
my ($ws, $frame) = @_;
say "Fin: $frame->[0]";
say "Rsv1: $frame->[1]";
say "Rsv2: $frame->[2]";
say "Rsv3: $frame->[3]";
say "Op: $frame->[4]";
say "FIN: $frame->[0]";
say "RSV1: $frame->[1]";
say "RSV2: $frame->[2]";
say "RSV3: $frame->[3]";
say "Opcode: $frame->[4]";
say "Payload: $frame->[5]";
});
Expand Down Expand Up @@ -447,9 +447,24 @@ C<CLOSE> frames automatically.
Build WebSocket frame.
# Build single "Binary" frame
# Continuation frame with FIN bit and payload
say $ws->build_frame(1, 0, 0, 0, 0, 'World!');
# Text frame with payload
say $ws->build_frame(0, 0, 0, 0, 1, 'Hello');
# Binary frame with FIN bit and payload
say $ws->build_frame(1, 0, 0, 0, 2, 'Hello World!');
# Close frame with FIN bit and without payload
say $ws->build_frame(1, 0, 0, 0, 8, '');
# Ping frame with FIN bit and payload
say $ws->build_frame(1, 0, 0, 0, 9, 'Test 123');
# Pong frame with FIN bit and payload
say $ws->build_frame(1, 0, 0, 0, 10, 'Test 123');
=head2 C<client_challenge>
my $success = $ws->client_challenge;
Expand Down Expand Up @@ -518,11 +533,11 @@ Parse WebSocket frame.
# Parse single frame and remove it from buffer
my $frame = $ws->parse_frame(\$buffer);
say "Fin: $frame->[0]";
say "Rsv1: $frame->[1]";
say "Rsv2: $frame->[2]";
say "Rsv3: $frame->[3]";
say "Op: $frame->[4]";
say "FIN: $frame->[0]";
say "RSV1: $frame->[1]";
say "RSV2: $frame->[2]";
say "RSV3: $frame->[3]";
say "Opcode: $frame->[4]";
say "Payload: $frame->[5]";
=head2 C<remote_address>
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -33,7 +33,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Leaf Fluttering In Wind';
our $VERSION = '2.77';
our $VERSION = '2.78';

# "These old doomsday devices are dangerously unstable.
# I'll rest easier not knowing where they are."
Expand Down

0 comments on commit 2ca4a81

Please sign in to comment.