Hi there people.
I'm having a huge problem when using fsockopen to connect to a udp socket. If the server I connect to does not respond then it still creates the filepointer so "if (!fp){" does not work to check wether it successfully connected or not. So then it goes next in the script and tries to read from the filepointer even though the other side does not excist.
In short the script is something like this...
$fp = fsockopen("udp://" . "snoggur.isnet.is", "27025", &$errno, &$errstr, 10);
if (!$fp)
{
//unable to connect to host
$serverinfo["name"] = "Error connecting to server";
}
else
{
fwrite($fp,"ÿÿÿÿdetails\x00");
// Get rid of the header
$header = fread($fp,5);
$do = true;
$result = "";
while($do)
{
$str = fread($fp,1);
$result .= $str;
if ($str == "\x00") $do = false;
}
$serverinfo["address"] = $result;
// Close the connection
fclose($fp);
}
This is higly anoying... What am I doing wrong????