Multiple Socket Read and Writes?
| From: | Dev | Date: | Tue, 24 Feb 2004 16:19:26 +0000 |
| Subject: | Multiple Socket Read and Writes? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-178725@lists.php.net to get a copy of this message | ||
Hello all,
I am having a problem with getting multiple socket reads working in a simple socket server!
The writes appear to be working but the reads seam to only allow one read?
I know i am missing something. Could even be my approach is totally wrong
Currently I have:
$input = socket_read($client[$i]['sock'] , 2024,PHP_BINARY_READ );
if ($input == null) {
// Zero length string meaning disconnected
echo "null input 1\n";
unset($client[$i]);
}
elseif ($input == 'exit') {
// requested disconnect
echo "exit\n";
socket_shutdown($client[$i]['sock']);
socket_close($client[$i]['sock']);
}
elseif ($input=="kill") {
echo "kill\n";
socket_shutdown($sock);
socket_close($sock);
die;
}
elseif ($input) {
// strip white spaces and write back to user
echo " <-- ". $input."\n";
socket_write( $client[$i]['sock'],dechex(50) );
echo " --> SYN ".socket_strerror(socket_last_error())."\n";
socket_write( $client[$i]['sock'],dechex(50) );
echo " --> SYN ".socket_strerror(socket_last_error())."\n";
socket_write( $client[$i]['sock'],dechex(50) );
echo " --> SYN ".socket_strerror(socket_last_error())."\n";
//$output = ereg_replace("[ \t\n\r]","",$input).chr(0);
if ( false == ( socket_write( $client[$i]['sock'],dechex(46) ) ) ) {
echo "socket_write() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
}
else {
echo " --> ENQ ".socket_strerror(socket_last_error())."\n";
$input1 = socket_read($client[$i]['sock'] , 2024,PHP_BINARY_READ );
echo "<-- ". $input1." " . socket_strerror(socket_last_error()) ."\n";
};
}
else {
echo "nothing on INPUT\n";
}
----------
UMPA
Brian C. Doyle
Director, Internet Services
United Merchant Processing Association
<http://www.umpa-us.com>http://www.umpa-us.com
1-800-555-9665 ext 212