PDA

View Full Version : "fsockopen" - Does Nothing for Me


D3VIANCE
09-15-2003, 08:43 PM
Please help! I'm not a coding n00b - not by any stretch. On the other hand, I'm not an expert with sockets. I've tried the most basic of examples, and still nothing. I can't connect to anything, even my own machine.

I'm simply trying to query a game server with the fsockopen command. Here's an example of a Jolt server that's always on:


<?php
$fp = fsockopen("udp://195.149.21.46", 28950, $errno, $errstr);
if (!$fp) {
echo "ERROR: $errno - $errstr<br>\n";
} else {
fwrite($fp,"\n");
echo fread($fp, 26);
fclose($fp);
}
?>

So what's wrong with this picture? Why will it not do anything?

Here it is, running on my server. It's an expensive server with 1&1 Hosting, Professional package:

http://www.clanplay.com/fsockopen.php

See? Times out. Does chuff all. Please help me! I'm running leagues, ladders, you name it on Clanplay, and I'm trying to develop a ranking system for SoF - but I can't even get past stage 1.

There's a big kiss in it for the first person who can get server queries working on my server. https://vborg.vbsupport.ru/

By the way, fsockopen isn't disabled. Here's a link to my phpinfo.php:

CLICK HERE (http://resources.winslow-clan.com/check-php.php)

D3VIANCE
09-15-2003, 10:25 PM
Okay, I've made advances. It is NOT "fsockopen" that is hanging, but "fread"!!! This code works fine:


<?php
$host = 'udp://195.149.21.46';
$port = 28950;
$fp = fsockopen($host, $port, &$err_no, &$err_msg, 10)
or die ("Could not open a socket connection to host <i>$host</i> on port <i>$port</i>.
The error message returned was '<i>$err_msg</i>'.");
echo "A socket connection to host <i>$host</i> on port <i>$port</i> was successfully opened.";
?>

http://www.clanplay.com/fsockopen-udp.php

I can run that all day long. However, as soon as I add the "fread" command I'm completely buggered.

Well, it's not much good being able to open a port unless you can read something from it. Even if I could just grab the first few bytes I'd break open a bottle of champagne, I swear to God...

Any ideas?