December 8th, 2003 07:37 PM
perl socket problem
I try to build a scanner with Perl using non blocking sockets & select calls.
The problem is the socket handle seems to close after reading all available datas
Could someone explain me what's wrong with this?
my $sel = new IO::Select();
for ($i=0;$i<2;$i ++)
my $host = '169.254.99.45';
my $port = 999;
my $proto = getprotobyname('tcp');
socket(Socket_Handle, PF_INET, SOCK_STREAM, $proto);
my $sin = sockaddr_in($port,inet_aton($host));
my $temp = 1;
ioctl(Socket_Handle, 0x8004667E, \$temp);
print "create socket\n";
my @ready_r = $sel->can_read();
foreach $sr (@ready_r)
#print "$sr ready to read";
my $sender = recv($sr, $line, 10, 0);
my @ready_w = $sel->can_write();
foreach $sw (@ready_w)
print "$sw ready to write";
#my @ready_e = $sel->has_exception();
#foreach $se (@ready_e)
# print "$se error pending";
Another problem is the hasexception method which seems to hang on forever...
Thanks for you help
December 8th, 2003 07:42 PM
I'm not an expert at Perl, but much of the syntax seems to be the same as C, C++, and several other languages....
I don't see anything wrong with your code, atleast nothing that jumps out, but you might want to put the whole thing in a loop, or set in a Goto type thing so that when the data flow stops, it goes back to the beginning of the code to check for more information, and continually does this until it sees that more information is coming in.