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
How are you storing the socket in $client[$i]['sock']? Like This:? $socket = socket_create(...); $client[$i]['sock']; You need to do it like this: $client[$i]['sock'] = socket_create(...); Why are you using something like this anyways though? Wouldn't it be easier to use some sort of daemon? When processing one client your script will not be able to handle any of the others if you use the way you are using now. However, if you run it as a daemon, forking the process everyone someone connects, then it will be a separate process for each client and you wont have latency issues. Just a thought. Matt
signature.asc
Description: This is a digitally signed message part