NAME

Net::Async::WebSocket::Server - serve WebSocket clients using IO::Async

SYNOPSIS

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

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

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

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

$server->listen(
   service => 3000,

   on_listen_error => sub { die "Cannot listen - $_[-1]" },
   on_resolve_error => sub { die "Cannot resolve - $_[-1]" },
);

$loop->loop_forever;

DESCRIPTION

This subclass of IO::Async::Listener accepts WebSocket connections. When a new connection arrives it will perform an initial handshake, and then pass the connection on to the continuation callback or method.

PARAMETERS

The following named parameters may be passed to new or configure:

on_client => CODE

A callback that is invoked whenever a new client connects and completes its inital handshake.

$on_client->( $self, $client )

It will be passed a new instance of a Net::Async::WebSocket::Protocol object, wrapping the client connection.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>