I am using PHP 4.2.1 under Windows XP. I am having trouble getting
socket_select to work on a UDP socket. Here is my code:

//Create socket
$socket = socket_create(AF_INET, SOCK_DGRAM, 0);
if ($socket < 0)
  echo "unable to create socket(".socket_strerror($socket);
  echo "OK";

//enable broadcasts
socket_setopt($socket, SOL_SOCKET, SO_BROADCAST, 1);

//first, a UDP broadcast command goes out
//I have verified with EtherPeek that this is indeed going out
if (socket_sendto($socket,$packet,$size,0,$IPBroadcast,$TCPIQPort) !=
  echo "failed";
  echo "OK";

//now call socket_select repeatedly for five seconds
$endtime = Time() + 5;
while (Time() < $endtime) {
  $r = array($socket);
  if (socket_select($r, $w=null, $e=null, 0) > 0) {
    echo "\n<P>readable";
    if (socket_recvfrom($socket, $buffer, 2048, 0, $addr, $port))  
      echo "\n<P>$buffer";

I never see $socket being readable, i.e. a return value from
socket_select greater than 0. I also can see in EtherPeek that UDP
packets are being sent back to this socket in response to the

Any help would be appreciated.


Bruce Vander Werf

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to