File: 04_send.t

package info (click to toggle)
libio-socket-multicast-perl 1.12-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 148 kB
  • sloc: perl: 216; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 751 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/perl
use strict;
BEGIN {
	$| 
 = 1;
	$^W = 1;
}

use Test::More;
use IO::Socket::Multicast;

plan skip_all => 'Developer testing only'
    unless (defined $ENV{TEST_UNSAFE} && $ENV{TEST_UNSAFE} == 1);

plan tests => 4;

my $MCAST_ADDR = '225.0.0.1';
my $MCAST_PORT = 9999;

my $s = IO::Socket::Multicast->new(
    LocalPort => $MCAST_PORT,
    Blocking  => 0,
);

$s->mcast_loopback(1);

my $payload =  "IO::Socket::Multicast test packet - $$ $0";

ok( $s->mcast_add( $MCAST_ADDR ) , "Join $MCAST_ADDR" );
ok( 
    $s->mcast_send( $payload ,"$MCAST_ADDR:$MCAST_PORT") , 
    "Send to $MCAST_ADDR:$MCAST_PORT" 
);

my $data;
ok( $s->recv( $data, 1024 ) , 'Received test data' );
ok( $data eq $payload , 'Received data matches sent data' );