| 
	
 | 
 Posted by Adam on 09/30/05 09:16 
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($remote_IP, $portNumber, $errno, $errstr, 
2); 
	if (!$handle) { 
		echo "$errno : $errstr <br/>"; 
	} 
	socket_set_timeout ($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_option() 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_strerror(socket_last_error($sock))."<br>\n"; 
		} elseif (!socket_bind($sock,"0.0.0.0",2934)) { 
		echo "<b>Error:</b> Failed to bind socket, 
".socket_strerror(socket_last_error($sock))."<br>\n"; 
		socket_close($sock); 
		} else { 
		socket_set_option($sock,SOL_SOCKET,SO_REUSEADDR,1); 
		socket_set_option($sock,SOL_SOCKET,SO_RCVTIMEO, 
array("sec"=>4, "usec"=>0));		 
 //$size=socket_recvfrom($sock,$buf,65535,1,$clientIP,$clientPort); 
		$buf=@socket_read($sock,2048); 
		if ($buf===FALSE) { 
			//echo "<b>Error:</b> Returned false, 
".socket_strerror(socket_last_error($sock))."<br>\n"; 
			echo "<b>OFFLINE</b>"; 
		} else { 
			echo strlen($buf) . ":" . $buf; 
		}		 
	echo "<hr>"; 
	flush(); 
	socket_close($sock); 
	} 
}; 
 
======================
 
  
Navigation:
[Reply to this message] 
 |