Hi,
Wednesday, February 25, 2004, 2:19:26 AM, you wrote:
D> Hello all,
D> I am having a problem with getting multiple socket reads working in a
D> simple socket server!
D> The writes appear to be working but the reads seam to only allow one read?
D> I know i am missing something. Could even be my approach is totally wrong
D> Currently I have:
D> $input = socket_read($client[$i]['sock'] , 2024,PHP_BINARY_READ );
D> if ($input == null) {
D> // Zero length string meaning disconnected
D> echo "null input 1\n";
D> unset($client[$i]);
D> }
D> elseif ($input == 'exit') {
D> // requested disconnect
D> echo "exit\n";
D> socket_shutdown($client[$i]['sock']);
D> socket_close($client[$i]['sock']);
D> }
D> elseif ($input=="kill") {
D> echo "kill\n";
D> socket_shutdown($sock);
D> socket_close($sock);
D> die;
D> }
D> elseif ($input) {
D> // strip white spaces and write back to user
D> echo " <-- ". $input."\n";
D> socket_write( $client[$i]['sock'],dechex(50) );
D> echo " --> SYN
D> ".socket_strerror(socket_last_error())."\n";
D> socket_write( $client[$i]['sock'],dechex(50) );
D> echo " --> SYN
D> ".socket_strerror(socket_last_error())."\n";
D> socket_write( $client[$i]['sock'],dechex(50) );
D> echo " --> SYN
D> ".socket_strerror(socket_last_error())."\n";
D> //$output = ereg_replace("[ \t\n\r]","",$input).chr(0);
D> if ( false == ( socket_write(
D> $client[$i]['sock'],dechex(46) ) ) ) {
D> echo "socket_write() failed: reason: " .
D> socket_strerror(socket_last_error()) . "\n";
D> }
D> else {
D> echo " -->
D> ENQ ".socket_strerror(socket_last_error())."\n";
D> $input1 =
D> socket_read($client[$i]['sock'] ,
D> 2024,PHP_BINARY_READ );
D> echo "<-- ". $input1." " .
D> socket_strerror(socket_last_error()) ."\n";
D> };
D> }
D> else {
D> echo "nothing on INPUT\n";
D> }
D> ----------
D> UMPA
D> Brian C. Doyle
D> Director, Internet Services
D> United Merchant Processing Association
D> <http://www.umpa-us.com>http://www.umpa-us.com
D> 1-800-555-9665 ext 212
To deal with multiple sockets have a look at socket_select()
--
regards,
Tom
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php