Jump to content

Connecting with UDP


frozenfire89

Recommended Posts

Ok, this is specific to the Half-Life game engine, so anyone with no experience in such may not be able to help.

 

Here is my script:

 

$ServerIP = "8.6.3.239";
$ServerPort = "27015";

$ServerinfoCommand = "\377\377\377\377infostring\0";

$fp = fsockopen("udp://".$ServerIP, $ServerPort, $errno, $errstr);

stream_set_timeout($fp, 10);

fwrite($fp, $ServerinfoCommand);

$JunkHead = fread($fp,24);

$CheckStatus = socket_get_status($fp);

if($CheckStatus["unread_bytes"] == 0)
{
    die("A connection to the server could not be made.");
}

$do = 1;
$HLServerStats= "";
while($do)
{
    $str = fread($fp,1);
    $HLServerStats.= $str;
    $CheckStatus = socket_get_status($fp);
    if($CheckStatus["unread_bytes"] == 0) {$do = 0;}
}

fclose($fp);

$HLServerStats = explode("\\", $HLServerStats);

$count = count($HLServerStats);

if($count % 2 == 0)
{
    $i = 0;
    while($count != $i)
    {
        $ServerData[$HLServerStats[$i]] = $HLServerStats[$i+1];
        $i = $i + 2;
    }
} 

echo($ServerData["address"]."\n<br>");

 

The problem I am having is that no connection is being made to the server. I know the server is up, and accepting requests, but it does not seem to work. What I do know is that the connection times out after the 10 second timeout I specify.

 

My reference for this is: http://collective.valve-erc.com/index.php?doc=1063146620-20111500

Link to comment
https://forums.phpfreaks.com/topic/51535-connecting-with-udp/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.