Hi there,
I\'m currently developing a friendly class-based wrapper for querying game servers and am having some problems with my UDP queries. Currently I had this problem solved but now it no longer seems to work.
The problem being the formatting of the query.
e.g. for halflife.
$query = \"ÿÿÿÿdetails\x00\";
Now thats my query which will be sent to the server, the full connection and grabbing the return is as follows.
$fp = fsockopen(\"udp://$this->ip\", $this->port, &$errno, &$errstr, 1);
if(!$fp)
die(\"Connection Failed!<br>\");
$query = \"ÿÿÿÿdetails\\x00\";
fwrite($fp,$query);
$chars = 0;
$read = 0;
$done = false;
while(!$done)
{
$chars++;
$str = fread($fp, 1);
$this->serverdata .= $str;
if($str == \"\\x00\")
$read++;
if($read == 11)
$done = true;
}
fclose($fp);
Now this doesn\'t work, it gets stuck in an endless loop at somepoint and doesn\'t return anything. I\'ve checked to make sure the address is correct when passed to the function. The script reads through one char at a time until it finds 11 null values (\"\x00\" which are line terminators?) then ends.
Subsequent to this I\'ve searched around a bit and found another sample on these forums. Now when I use thier code...
$fp = fsockopen(\"udp://212.140.216.88\", 37108, &$errno, &$errstr,1);
fwrite($fp,\"ÿÿÿÿdetails\x00\");
$got = 0;
$max = 0;
$done =0;
$do = true;
while($do)
{
$max++;
$str = fread($fp, 1);
$buffer .= $str;
if($str == \"\x00\")
$done++;
if($done == 11)
$do = false;
}
fclose($fp);
I was shocked to find that it works with no problems at all. With nearly identical code too albeit in flat files. Now to check mine out against it I placed my code into a flat file to just grab the output and it still hangs up somewhere (most likely in the while loop) and my only explanation is that my \x00 must differ somehow to the other code!
Any suggestions are appreciated!