Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Basic tests for UDP sockets.
  • Loading branch information
jnthn committed Dec 14, 2015
1 parent ce74fd9 commit de38b0b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions S32-io/IO-Socket-Async-UDP.t
@@ -0,0 +1,36 @@
use v6;
use Test;

plan 2;

my $hostname = 'localhost';
my $port = 5001;

# Promise used to check listener received data, and to make
my $rec-prom;

# Listener
{
my $sock = IO::Socket::Async.bind-udp($hostname, $port);
my $tap = $sock.Supply.tap: -> $chars {
$rec-prom.keep($chars);
}
}

# Client print-to
{
$rec-prom = Promise.new;
my $sock = IO::Socket::Async.udp();
$sock.print-to($hostname, $port, "Unusually Dubious Protocol");
is $rec-prom.result, "Unusually Dubious Protocol", "Sent/received data with UDP (print)";
$sock.close;
}

# Client write-to
{
$rec-prom = Promise.new;
my $sock = IO::Socket::Async.udp();
$sock.write-to($hostname, $port, "Unhelpful Dataloss Protocl".encode('ascii'));
is $rec-prom.result, "Unhelpful Dataloss Protocl", "Sent/received data with UDP (write)";
$sock.close;
}

0 comments on commit de38b0b

Please sign in to comment.