Server Detector no longer working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RonHiler

    Server Detector no longer working

    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)

    <?php
    if(($sock = socket_create (AF_INET, SOCK_DGRAM, 0)) < 0)
    {
    echo "socket_create( ) failed: reason: " . socket_strerror ($sock) .
    "<BR>";
    }
    else
    {
    $server='xx.xxx .xx.xx';
    $port=yyyy;
    $send=sprintf(' %c%c%c%c',24, 0, 0, 0);
    $x=socket_sendt o($sock,$send,s trlen($send)-1,0,$server,$po rt);

    $bar = array($sock);
    $select_result = socket_select($ bar, $b=null, $c=null, 3);
    if ($select_result == true)
    {
    $y=socket_recvf rom($sock,&$rec vbuf,1024,0,&$f rom,&$port);
    $LauncherPopula tion = sprintf('%d%d%d %d%d',$recvbuf[0],
    $recvbuf[1],
    $recvbuf[2], $recvbuf[3], $recvbuf[4]);
    $LauncherPopula tion = ltrim($Launcher Population, '0');
    if ($LauncherPopul ation == '')
    $LauncherPopula tion = '0';
    $ClientPopulati on = sprintf('%d%d%d %d%d',$recvbuf[5], $recvbuf[6],
    $recvbuf[7], $recvbuf[8], $recvbuf[9]);
    $ClientPopulati on = ltrim($ClientPo pulation , '0');
    if ($ClientPopulat ion == '')
    $ClientPopulati on = '0';

    echo "<CENTER>Th e Sovereignty Server<BR>";
    echo "is UP</CENTER><BR>";
    ?>
    <CENTER><img src="GreenGem.p ng" border="0"></CENTER>
    <?php
    echo "<CENTER>Launch er Population: " . $LauncherPopula tion .
    "<BR>";
    echo "Client Population: " . $ClientPopulati on .
    "</CENTER><BR><BR> ";
    }
    else
    {
    echo "<CENTER>Th e Sovereignty Server<BR>";
    echo "is DOWN</CENTER><BR>";
    ?>
    <CENTER><img src="RedGem.png " border="0"></CENTER>
    <?php
    }
    }
    socket_close($s ock);
    ?>

    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
    from).

    Thanks for any advice.

    Ron
Working...