Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.