473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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_sendto($sock,$send,strlen($send)-1,0,$server,$port);

$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[1],
$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>
<?php
echo "<CENTER>Launcher Population: " . $LauncherPopulation .
"<BR>";
echo "Client Population: " . $ClientPopulation .
"</CENTER><BR><BR>";
}
else
{
echo "<CENTER>The Sovereignty Server<BR>";
echo "is DOWN</CENTER><BR>";
?>
<CENTER><img src="RedGem.png" border="0"></CENTER>
<?php
}
}
socket_close($sock);
?>

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
Jul 17 '05 #1
0 1439

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joh | last post by:
Hello, (sorry long) i think i have missed something in the code below, i would like to design some kind of detector with python, but i feel totally in a no way now and need some advices to...
43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
4
by: Chinmoy Mukherjee | last post by:
Hi All, Do you know of any free memory leak detector for C++ for windows OS? Regards, Chinmoy
2
by: Leon Lambert | last post by:
I was wondering if someone could post some links to some bug pattern detector software for C#. I found this very interesting article about pattern detectors for Java so wanted to investiage one for...
24
by: Jim Michaels | last post by:
I can't get any "universal" code working that tries to detect whether the document it's in is xhtml or html. I found this, which tells me I have a hill to climb with no equipment....
1
by: Lighter | last post by:
Is there a way to write a memory leak detector supporting new(nothrow)? For example, #include <My_Debug_New.h> using namespace std; int main() {
5
by: Lalit | last post by:
Hi Group, I have discovered a technique by which we can be able to detect if a particular font is present in a user's machine. Below is a brief info about the script. You can find more info at...
4
by: cnixuser | last post by:
Hello, I am attempting to create a prime number detector that will identify all of the prime numbers within a specified range of numbers. The problem is, for some reason my program is not detecting...
0
by: Dmitriy V'jukov | last post by:
I want to announce release 1.1 of Relacy Race Detector. First of all, now you can freely DOWNLOAD latest version of Relacy Race Detector DIRECTLY FROM WEB:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.