The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::Async::WebSocket::JSON::Server - server WebSocket clients using JSON and IO::Async

SYNOPSIS

 use IO::Async::Loop;
 use Net::Async::WebSocket::JSON::Server;

 my $server = Net::Async::WebSocket::JSON::Server->new(
    on_client => sub {
       my ( undef, $client ) = @_;

       $client->configure(
          on_json => sub {
             my ( $self, $frame ) = @_;
             $self->send_json( $frame );
          },
       );
    }
 );

 my $loop = IO::Async::Loop->new;
 $loop->add( $server );

 $server->listen(
    service => 3000,
 )->get;

 $loop->run;

DESCRIPTION

This subclass of Net::Async::WebSocket::Server provides conveniences for using JSON-encoded data sent over text frames.

It should be used identically to Net::Async::WebSocket::Server, except that connected client instances will be instances of Net::Async::WebSocket::JSON::Protocol, and have the new send_json method and on_json event available.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>