|
Posted by Adam on 10/29/08 11:27
On Wed, 21 Sep 2005 07:05:41 -0500, Jerry Stuckle wrote:
>Adam wrote:
>> Hi! I'm trying to write a small application for an online gaming site
>> (flight sims), where people can add their local server to a list.
>>
>> Basically, I just need to be able to loop/ping each respective server
>> - via a specific port (2934 or 2935) to see whether the server is
>> still "live", so the hosters don't have to manually update their
>> status on the site.
>>
>> Everything I've seen seems overly complex. Efforts so far have
>> returned info via a traditional PING, but I can't seem to find an easy
>> way of getting the required *port* info. The script would have to run
>> from a regular hosted site, so I wouldn't have much access to the
>> server's "innards".
>>
>> Any ideas?
>>
>> TIA - Adam.
>
>Ping uses an internally defined port for responses - not just any port.
> You can't ping a specific port - it wouldn't know how to respond.
>
>Probably the easiest way would be to use fsockopen to open a socket to
>the appropriate system/port.
Thanks for that. I've managed to send an initial "handshake" packet
out to the game server using:
$handle = fsockopen("udp://$host", $port, $errno, $errstr, $timeout);
It triggers the game server to respond with a 67 byte long reply
(which I can see using a packet sniffer). So far so good.
However ... try as I might, I just can't read this data. I've tried
all sorts of combinations of "fread", "unpack" etc. eg:
$contents = fread($handle, 67);
The above seems to return nothing. How do I go about reading this
packet of data? Is the PHP code executing before the packet has had a
chance to arrive?
Thanks,
Adam.
Navigation:
[Reply to this message]
|