Persistent Socket Connection

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ChoKamir
Forum Newbie
Posts: 1
Joined: Sun Oct 12, 2003 12:55 pm

Persistent Socket Connection

Post by ChoKamir »

Hello

I've been making a server in visual basic and now i'm busy with the website suporting the game server. I made a simple script to show the amount of clients connected to the game server and which characters are logged in. The problem is I don't want to connect to the server everytime some one views the page. I read about persistent connection and they seemed to be the solution. But some how it doesn't work.
Here is my code i use:


VB:
--------------------------------------------------------------------------------
$fp = pfsockopen ('80.61.74.5', 3334, $errno, $errstr, 30);
//Checks If there still Is no connection
If (!$fp) {
$serverState = "Offline";
$usersOnline = "";
$charsOnline = "";
} Else {
$serverState = "Online";
fputs ($fp, "0\r\n");
$res = fgets($fp,2048);
$res = trim($res) . ",";

$usersOnline = substr($res,strpos($res,',')+1,strpos($res,',',strpos($res,',')+1)-strpos($res,',')-1);
$charsOnline = substr($res,strpos($res,',',strpos($res,',')+1)+1);
$charsOnline = str_replace(",","<br>",$charsOnline);
echo $res;
}

echo $serverState;
echo "<br>";
echo $usersOnline;
echo "<hr>";
echo $charsOnline;
echo "<br>";
--------------------------------------------------------------------------------



The problem is that still everytime a user views the page it opens a new connection and doesn't reuse the old one. What do i do wrong:S

Thx ChoKamir

__________________
"Who gets weaker? The king or the teacher
It's not about a salary it's all about reality
Teachers teach and do the world good
kings just rule and most are never understood" - KRS-One
Post Reply