This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
3e1671411822b044000c125a600bb89625c4901b
[perl5.git] / t / lib / io_udp.t
1 #!./perl
2
3 BEGIN {
4     unless(grep /blib/, @INC) {
5         chdir 't' if -d 't';
6         @INC = '../lib' if -d '../lib';
7     }
8 }
9
10 use Config;
11
12 BEGIN {
13     if(-d "lib" && -f "TEST") {
14         if ( ($Config{'extensions'} !~ /\bSocket\b/ ||
15               $Config{'extensions'} !~ /\bIO\b/ ||
16               $^O eq 'os2')    &&
17               !(($^O eq 'VMS') && $Config{d_socket})) {
18             print "1..0\n";
19             exit 0;
20         }
21     }
22 }
23
24 $| = 1;
25 print "1..3\n";
26
27 use Socket;
28 use IO::Socket qw(AF_INET SOCK_DGRAM INADDR_ANY);
29
30     # This can fail if localhost is undefined or the
31     # special 'loopback' address 127.0.0.1 is not configured
32     # on your system. (/etc/rc.config.d/netconfig on HP-UX.)
33
34 $udpa = IO::Socket::INET->new(Proto => 'udp', LocalAddr => 'localhost');
35 $udpb = IO::Socket::INET->new(Proto => 'udp', LocalAddr => 'localhost');
36
37 print "ok 1\n";
38
39 $udpa->send("ok 2\n",0,$udpb->sockname);
40 $udpb->recv($buf="",5);
41 print $buf;
42 $udpb->send("ok 3\n");
43 $udpa->recv($buf="",5);
44 print $buf;