On Mon, 26 Sep 2005 13:11:20 -0500, Jerry Stuckle wrote:
I really wish I could be more help here - but this is a problem I
haven't run into before.
Jerry - success!!!
I finally got it working - but what an ordeal!!
1) It seems that socket support in PHP is "flakey" to say the least. I
followed a few of the bug threads on PHP.net - some seem to indicate
that old bugs have been re-inroduced in PHP5 :-(
2) A lot of the socket related functions don't work on the Win32 PHP
exes (probably because the socket support isn't "pre-compiled" <??>.
3) The documentation is really far from clear - particularly with
vital differences due to the "connection-less state" of UDP.
4) For the life of me I *still* can't get fread() to work - fwrite()
works fine.
Anyway - it shows that the firewall was never the problem.
So ... thanks for persevering with me!
Adam.
=============== ===========
Here's the code:
Eventually, the script will loopo through a D/B query, but here's a
temporary loop through the 2 local test sim servers:
First the "hello" message gets sent:
$sites_array = array("192.168. 1.20", "192.168.1.126" );
foreach ($sites_array as $site_ip) {
$remote_IP = 'udp://';
$remote_IP .= $site_ip;
$portNumber = 2934;
$handle = fsockopen($remo te_IP, $portNumber, $errno, $errstr,
2);
if (!$handle) {
echo "$errno : $errstr <br/>";
}
socket_set_time out ($handle, 2);
$write = fwrite($handle, $hello);
if (!$write) {
echo "OOPS! Error writing to port: $portNumber.<br/>";
} else {
echo "Query sent to $remote_IP : $portNumber. <br/>";
};
fclose($handle) ;
Then the read of the response (note the use of socket_set_opti on() to
set the time-out etc.). Also, socket_recvfrom () seemed to work as
well.
if (!$sock=socket_ create(AF_INET, SOCK_DGRAM,SOL_ UDP)) {
echo "<b>Error:</b> Failed to create socket,
".socket_strerr or(socket_last_ error($sock))." <br>\n";
} elseif (!socket_bind($ sock,"0.0.0.0", 2934)) {
echo "<b>Error:</b> Failed to bind socket,
".socket_strerr or(socket_last_ error($sock))." <br>\n";
socket_close($s ock);
} else {
socket_set_opti on($sock,SOL_SO CKET,SO_REUSEAD DR,1);
socket_set_opti on($sock,SOL_SO CKET,SO_RCVTIME O,
array("sec"=>4, "usec"=>0)) ;
//$size=socket_re cvfrom($sock,$b uf,65535,1,$cli entIP,$clientPo rt);
$buf=@socket_re ad($sock,2048);
if ($buf===FALSE) {
//echo "<b>Error:</b> Returned false,
".socket_strerr or(socket_last_ error($sock))." <br>\n";
echo "<b>OFFLINE </b>";
} else {
echo strlen($buf) . ":" . $buf;
}
echo "<hr>";
flush();
socket_close($s ock);
}
};
=============== =======