By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,443 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,443 IT Pros & Developers. It's quick & easy.

Server Detector no longer working

P: n/a
Hi guys,

I run a game server (for a game I'm writing in development). I had a
routine on my web site which detected if the server was up or down and
displayed a icon, so that people could see from the web page if the
server was working or not.

I just changed where my web page is hosted, and the routine no longer
works, and I can't figure out why. Can anyone give me any clues?

Here is the routine (taking out the IP address and port numbers)

if(($sock = socket_create (AF_INET, SOCK_DGRAM, 0)) < 0)
echo "socket_create() failed: reason: " . socket_strerror($sock) .
$send=sprintf('%c%c%c%c',24, 0, 0, 0);

$bar = array($sock);
$select_result = socket_select($bar, $b=null, $c=null, 3);
if ($select_result == true)
$y=socket_recvfrom($sock,&$recvbuf,1024,0,&$from,& $port);
$LauncherPopulation = sprintf('%d%d%d%d%d',$recvbuf[0],
$recvbuf[2], $recvbuf[3], $recvbuf[4]);
$LauncherPopulation = ltrim($LauncherPopulation, '0');
if ($LauncherPopulation == '')
$LauncherPopulation = '0';
$ClientPopulation = sprintf('%d%d%d%d%d',$recvbuf[5], $recvbuf[6],
$recvbuf[7], $recvbuf[8], $recvbuf[9]);
$ClientPopulation = ltrim($ClientPopulation , '0');
if ($ClientPopulation == '')
$ClientPopulation = '0';

echo "<CENTER>The Sovereignty Server<BR>";
echo "is UP</CENTER><BR>";
<CENTER><img src="GreenGem.png" border="0"></CENTER>
echo "<CENTER>Launcher Population: " . $LauncherPopulation .
echo "Client Population: " . $ClientPopulation .
echo "<CENTER>The Sovereignty Server<BR>";
echo "is DOWN</CENTER><BR>";
<CENTER><img src="RedGem.png" border="0"></CENTER>

Any ideas why this no longer works? The current result is that the
page just hangs at this routine. My preliminary experiments seem to
suggest that $select_result now always returns true, even when the
server is off.

When the server is running, the code works fine, the green gem comes
up, the population values are correct. It's only when the server is
NOT running that the web page locks up. $select_result is definitely
returning a false positive when the server is down (which it didn't
used to do before). As a result, the page is locking up at the
recvfrom() line (because there is no server running to send the data

Thanks for any advice.

Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.