Subject: | Listening on UDP Sockets deos not work with recent versions of MSWin32 Perl |
Install latest Perl for Windows; I tried both:
- Strawberry Perl v5.26.1
- ActiveState Perl v5.22.4
(I'm only using the 32bit versions)
Both of the above come with latest IO::Socket::IP version 0.39
Use the simple example posted on this PerlMonks thread:
http://www.perlmonks.org/?node_id=129553
If you use IO::Socket::INET it works fine.
Replace with IO::Socket::IP and it does not work anymore.
In particular, what is not working is listening on UDP sockets.
IO::Socket::IP seems unable to receive on UDP sockets.
For some reason (which I am not able to determine), on older versions of Perl, IO::Socket::IP does work fine with UDP sockets. I have the above working fine on ActiveState v5.16.3 (32-bit version again) also with IO::Socket::IP version 0.39
Below are the simple test scripts I am using.
If there is any other info I need to provide do let me know.
Thanks in advance
Ludovico Stevens
Server script:
$|++;
use strict;
use IO::Socket;
use IO::Socket::IP;
#my $server = IO::Socket::IP->new(
my $server = IO::Socket::INET->new(
LocalPort => 10000,
Proto => "udp",
# ReuseAddr => 1,
) or die "Can't create UDP server: $@";
my ($datagram,$flags);
while ($server->recv($datagram,42,$flags)) {
my $ipaddr = $server->peerhost;
print "Oooh -- udp from $ipaddr, flags ",$flags || "none",": $datagram\n";
my $response = IO::Socket::INET->new(Proto=>"udp",PeerHost=>$ipaddr,PeerPort=>2424);
$response->send("PONG!");
}
Client script:
$|++;
use strict;
use IO::Socket;
use IO::Socket::IP;
#my $response = IO::Socket::IP->new(
my $response = IO::Socket::INET->new(
Proto => "udp",
LocalPort => 2424,
) or die "Can't make UDP server: $@";
#my $message = IO::Socket::IP->new(
my $message = IO::Socket::INET->new(
Proto => "udp",
PeerPort => 10000,
PeerAddr => "127.0.0.1",
# PeerAddr => "127.255.255.255",
) or die "Can't make UDP socket: $@";
$message->send("Ping!");
my ($datagram,$flags);
$response->recv($datagram,42,$flags);
print "Got message from ", $response->peerhost,", flags ",$flags || "none",": $datagram\n";