Skip to content

Commit

Permalink
more WebSocket examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 6, 2012
1 parent 68dec2f commit 5e4c694
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

3.38 2012-09-06
3.38 2012-09-07
- Added xor_encode method to Mojo::ByteStream.
- Added xor_encode function to Mojo::Util.
- Improved documentation.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Cookie/Response.pm
Expand Up @@ -116,7 +116,7 @@ Cookie domain.
my $httponly = $cookie->httponly;
$cookie = $cookie->httponly(1);
HttpOnly flag, which can prevent client side scripts from accessing this
HttpOnly flag, which can prevent client-side scripts from accessing this
cookie.
=head2 C<max_age>
Expand Down
12 changes: 6 additions & 6 deletions lib/Mojo/Transaction.pm
Expand Up @@ -198,19 +198,19 @@ implements the following new ones.
$tx->client_close;
Transaction closed.
Transaction closed client-side.
=head2 C<client_read>
$tx->client_read($chunk);
Read and process client data. Meant to be overloaded in a subclass.
Read and process data client-side. Meant to be overloaded in a subclass.
=head2 C<client_write>
my $chunk = $tx->client_write;
Write client data. Meant to be overloaded in a subclass.
Write data client-side. Meant to be overloaded in a subclass.
=head2 C<connection>
Expand Down Expand Up @@ -261,19 +261,19 @@ Remote interface address.
$tx->server_close;
Transaction closed.
Transaction closed server-side.
=head2 C<server_read>
$tx->server_read($chunk);
Read and process server data. Meant to be overloaded in a subclass.
Read and process data server-side. Meant to be overloaded in a subclass.
=head2 C<server_write>
my $chunk = $tx->server_write;
Write server data. Meant to be overloaded in a subclass.
Write data server-side. Meant to be overloaded in a subclass.
=head2 C<success>
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojo/Transaction/HTTP.pm
Expand Up @@ -300,13 +300,13 @@ implements the following new ones.
$tx->client_read($chunk);
Read and process client data.
Read and process data client-side.
=head2 C<client_write>
my $chunk = $tx->client_write;
Write client data.
Write data client-side.
=head2 C<keep_alive>
Expand All @@ -318,19 +318,19 @@ Check if connection can be kept alive.
my $leftovers = $tx->server_leftovers;
Leftovers from the server request, used for pipelining.
Leftovers from the request, used for pipelining server-side.
=head2 C<server_read>
$tx->server_read($chunk);
Read and process server data.
Read and process data server-side.
=head2 C<server_write>
my $chunk = $tx->server_write;
Write server data.
Write data server-side.
=head1 SEE ALSO
Expand Down
20 changes: 10 additions & 10 deletions lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -433,25 +433,25 @@ Build WebSocket frame.
my $success = $ws->client_challenge;
Check WebSocket handshake challenge.
Check WebSocket handshake challenge client-side.
=head2 C<client_handshake>
$ws->client_handshake;
WebSocket handshake.
Perform WebSocket handshake client-side.
=head2 C<client_read>
$ws->client_read($data);
Read raw WebSocket data.
Read and process data client-side.
=head2 C<client_write>
my $chunk = $ws->client_write;
Raw WebSocket data to write.
Write data client-side.
=head2 C<connection>
Expand Down Expand Up @@ -538,9 +538,9 @@ Resume C<handshake> transaction.
$ws = $ws->send({binary => $bytes});
$ws = $ws->send({text => $bytes});
$ws = $ws->send([$fin, $rsv1, $rsv2, $rsv3, $op, $payload]);
$ws = $ws->send('Hi there!');
$ws = $ws->send('Hi there!' => sub {...});
$ws = $ws->send([$fin, $rsv1, $rsv2, $rsv3, $op, $bytes]);
$ws = $ws->send($chars);
$ws = $ws->send($chars => sub {...});
Send message or frame non-blocking via WebSocket, the optional drain callback
will be invoked once all data has been written.
Expand All @@ -552,19 +552,19 @@ will be invoked once all data has been written.
$ws->server_handshake;
WebSocket handshake.
Perform WebSocket handshake server-side.
=head2 C<server_read>
$ws->server_read($data);
Read raw WebSocket data.
Read and process data server-side.
=head2 C<server_write>
my $chunk = $ws->server_write;
Raw WebSocket data to write.
Write data server-side.
=head1 DEBUGGING
Expand Down
14 changes: 10 additions & 4 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -808,16 +808,22 @@ browsers often don't really know what they actually want.
$c = $c->send({binary => $bytes});
$c = $c->send({text => $bytes});
$c = $c->send([$fin, $rsv1, $rsv2, $rsv3, $op, $payload]);
$c = $c->send('Hi there!');
$c = $c->send('Hi there!' => sub {...});
$c = $c->send([$fin, $rsv1, $rsv2, $rsv3, $op, $bytes]);
$c = $c->send($chars);
$c = $c->send($chars => sub {...});
Send message or frame non-blocking via WebSocket, the optional drain callback
will be invoked once all data has been written.
# Send JSON object as text frame
# Send "Text" frame
$c->send('Hello World!');
# Send JSON object as "Text" frame
$c->send({text => Mojo::JSON->new->encode({hello => 'world'})});
# Send JSON object as "Binary" frame
$c->send({binary => Mojo::JSON->new->encode({hello => 'world'})});
# Send "Ping" frame
$c->send([1, 0, 0, 0, 9, 'Hello World!']);
Expand Down

0 comments on commit 5e4c694

Please sign in to comment.