#! perl -slw use strict; use IO::Socket::INET; use threads; my $noBlock = 1; ## Create an array of udp listeners my @listeners = map{ my $listener = IO::Socket::INET->new( LocalPort => $_, Proto => 'udp', Reuse => 1, ## Blocking => 0, ## No apparent effect on Win32. ) or die $!, $^E; ioctl( $listener, 0x8004667e, \$noBlock ); ## non-blocking on Win32 $listener; } 10001 .. 10005; ## forever, but not too fast while( sleep 1 ) { my( $msg, $client ); ## iterate the listening ports for( 0 .. $#listeners ) { ## Read anything they have available ## Should check if there is more $client = $listeners[ $_ ]->recv( $msg, 1024, 0 ) ## and skip on if nothing there or warn "Nothing from $_\n" and next; ## Work out who's talking to us my( $port, $x ) = sockaddr_in( $client ); my $ip = inet_ntoa( $x ); ## And do **WHATEVER** with their message. print "$ip:$port : $msg" } }