L
Larry
hi folks,
I'd like to get 10 sockets listening on different ports in the same
process at the same time...can it actually be done?
here's a chunck of code:
#!/perl
use strict;
use warnings;
use Socket;
$| = 1;
my ($usock, $uport);
while (1)
{
($usock,$uport) = &udp_setup("127.0.0.1");
print $uport;
my $buff;
my $lbuff = 1024;
#while ( recv($usock, $buff, $lbuff, 0) )
#{
# print $buff;
#}
}
sub udp_setup
{
my $HOSTNAME = $_[0];
my $fh;
socket($fh, PF_INET, SOCK_DGRAM, getprotobyname("udp")) or return "";
binmode($fh);
my $ipaddr = inet_aton($HOSTNAME);
my $portaddr = sockaddr_in(0, $ipaddr);
bind($fh, $portaddr) or return "";
my ($nport, $naddr);
($nport, $naddr) = sockaddr_in(getsockname($fh));
return ($fh,$nport);
}
yet, the while {} block is blocking...
I'd like to get 10 sockets listening on different ports in the same
process at the same time...can it actually be done?
here's a chunck of code:
#!/perl
use strict;
use warnings;
use Socket;
$| = 1;
my ($usock, $uport);
while (1)
{
($usock,$uport) = &udp_setup("127.0.0.1");
print $uport;
my $buff;
my $lbuff = 1024;
#while ( recv($usock, $buff, $lbuff, 0) )
#{
# print $buff;
#}
}
sub udp_setup
{
my $HOSTNAME = $_[0];
my $fh;
socket($fh, PF_INET, SOCK_DGRAM, getprotobyname("udp")) or return "";
binmode($fh);
my $ipaddr = inet_aton($HOSTNAME);
my $portaddr = sockaddr_in(0, $ipaddr);
bind($fh, $portaddr) or return "";
my ($nport, $naddr);
($nport, $naddr) = sockaddr_in(getsockname($fh));
return ($fh,$nport);
}
yet, the while {} block is blocking...