note 59281 rejected from function.socket-listen by nicobn

From: Date: Tue, 03 Jul 2007 19:56:10 +0000
Subject: note 59281 rejected from function.socket-listen by nicobn
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-128192@lists.php.net to get a copy of this message
Note Submitter: ---- // How to set up a UDP polling service using a system trigger // avoiding intensive pooling loop // set up a socket $sux = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if (!$sux) exit('create error'); // designate a port on the socket to recieve data if (!socket_bind($sux, $local_ip, 2210)) exit('bind error'); $suxref[] =& $sux; // create a reference to the socket as an array $ip = ''; $port = 0; do { // let the system take care of polling for UDP data socket_select($suxref, $write = NULL, $except = NULL, 5); // sec. timout // get the UDPdata with the sender's IP/port $z = @socket_recvfrom($sux, $buf, 9999, 0, $ip, $port); // return some data to the sender IP/port if (strlen($buf) > 0) { echo "\r\nRemote sent: " . $buf; socket_sendto($sux, "I hear you", 9999, 0x4, $ip, $port); } } while(true);

« previous php.notes (#128192) next »