sub listen_thread { $udp_sock = IO::Socket::INET->new(PeerAddr => inet_ntoa(INADDR_BROADCAST), Proto => udp, LocalPort => 48888) or die "socket: $@"; my $s = new IO::Select($udp_sock); print "listen thread running\n"; #make sure the handle is registered @ready = $s->handles(); print "handles = \n"; foreach $r (@ready) { print "han: $r\n"; } #enter loop to receive packets while (1) { @ready = $s->can_read(5); print "waiting handles\n"; foreach $r (@ready) { print "rd $r\n"; } #see if we should terminate the thread if ($thread_stop == 1) { print "listen thread terminated\n"; $udp_sock->close; return 1; } # see if something is waiting print "th - $ready[0] - $udp_sock\n"; if ($ready[0] == $udp_sock) { print "th-r-wait\n"; $t = $udp_sock->recv($newmsg, 1400,0); print "th-r-done $t\n"; } else { print "listen thread timeout\n"; } } }