AnyEvent-WebSocket-Client
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
t/anyevent_websocket_client__ssl.t view on Meta::CPAN
use lib 't/lib';
use Test2::Require::SSL;
use Test2::Plugin::EV;
use Test2::Plugin::AnyEvent::Timeout;
use Test2::V0 -no_srand => 1;
use Test2::Tools::WebSocket::Server qw( start_server );
use AnyEvent::WebSocket::Client;
my $counter;
my $max;
my $uri = start_server(
tls => AnyEvent::TLS->new(cert => do { local $/; <DATA> }),
handshake => sub { # handshake
my $opt = { @_ };
$counter = 1;
$max = 15;
note "max = $max";
note "resource = " . $opt->{handshake}->req->resource_name;
if($opt->{handshake}->req->resource_name =~ /\/count\/(\d+)/)
{ $max = $1 }
note "max = $max";
},
message => sub { # message
my $opt = { @_ };
eval q{
note "send $counter";
$opt->{hdl}->push_write($opt->{frame}->new($counter++)->to_bytes);
if($counter >= $max)
{
$opt->{hdl}->push_write($opt->{frame}->new(type => 'close')->to_bytes);
$opt->{hdl}->push_shutdown;
}
};
},
);
$uri->path('/count/10');
note $uri;
my $connection = eval { AnyEvent::WebSocket::Client->new( ssl_no_verify => 1 )->connect($uri)->recv };
if(my $error = $@)
{
die $error;
}
isa_ok $connection, 'AnyEvent::WebSocket::Connection';
my $done = AnyEvent->condvar;
$connection->send('ping');
my $last;
$connection->on(each_message => sub {
my $message = $_[1]->body;
note "recv $message";
$connection->send('ping');
$last = $message;
});
$connection->on(finish => sub {
$done->send(1);
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.508 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )