This line... while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) {
...is what returns the error. The whole loop (which needs to keep running).
$msg_recv = 3;
do {
$data = "";
socket_set_block($socket);
socket_set_option($socket,SOL_SOCKET,SO_RCVTIMEO,$timeout);
while(($buf = socket_read($socket,128,PHP_BINARY_READ)) !== false) { // THIS IS WHERE IT CHOKES
$data .= $buf;
if(preg_match("/ENX/",$data)) {
$msg_recv = 1;
break;
} elseif ($error = socket_last_error($socket)) {
$msg_recv = 0;
echo "\nTIMEOUT: SOCKET ERROR [$error]:" . socket_strerror($error);
break;
}
}
if ($msg_recv == 1) { echo "\nMESSAGE RECEIVED\n"; $msg_recv = 3; } elseif ($msg_recv == 0) { echo "\nTIMEOUT: MESSAGE NOT RECEIVED\n"; $msg_recv = 3; }
} while ($connection == true);
And the output:
MESSAGE RECEIVED
MESSAGE RECEIVED
PHP Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 64
Warning: socket_read() unable to read from socket [35]: Resource temporarily unavailable in /Users/rene/Sites/gpspolice/titan/cr.php on line 64
On Thursday, May 13, 2004, at 04:44 PM, Tom Rogers wrote:
Hi,
Friday, May 14, 2004, 5:21:10 AM, you wrote: RF> Hi all,
RF> Still encountering some challenges with my socket loop. Basically, I
RF> need this socket client to wait to read incoming data, but if nothing
RF> happens for more than three seconds, I want it to do something, then
RF> return to waiting (for another three seconds). I've got some good help
RF> from Curt and Tom (thanks guys), but there are evidently still issues
RF> with my code. Here's simplified snippet:
you need to use break 2; to exit the while and the do - while or set $connection = false;
-- regards, Tom
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php