Quote:
>> Anyone got a reader for sockets that will know when to stop reading? I
>> haven't found any examples on the internet on how to do it, just that
>> everyone says it can be done. I'd really appreciate the help![/color]
>In my opinion you should use function $char=getc($server) in the loop and
>analyze text you reach in this way.
>In my programs it works very well.
See:
http://poe.perl.org/?POE_RFCs/Window..._compatibility
The problem is that non-blocking sockets don't work on NT. All sockets are forced to block and wait for a new-line or EOF. Using getc() and testing for some end marker is one way around it, but using sysread() works better. It reads as many chars as are in the buffer without blocking.
Ex.
$retries = 30;
$bytes_to_read = 1024;
do {
while ( sysread( $socket, $data, $bytes_to_read ) == $bytes_to_read )
{
$xyz .= $data;
}
last if $xyz =~ /endmarker/;
sleep 1;
} while --$retries;
This will try to read from the socket for about 30 seconds or until the end marker is found.
BTW, DO NOT try to use read() or recv() on the socket! See the perl docs on sysread() for more info.