|
Posted by Jerry Stuckle on 12/08/95 11:27
Adam wrote:
> On Wed, 21 Sep 2005 07:05:41 -0500, Jerry Stuckle wrote:
>
>
>
> 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.
From the PHP manual:
Warning:
UDP sockets will sometimes appear to have opened without an error, even
if the remote host is unreachable. The error will only become apparent
when you read or write data to/from the socket. The reason for this is
because UDP is a "connectionless" protocol, which means that the
operating system does not try to establish a link for the socket until
it actually needs to send or receive data.
So - just because you get a handle back doesn't mean you've successfully
opened the socket. You may not actually be opening it. You many need
to use a packet sniffer to see what's actually going across your link.
Otherwise, if just opening the socket gets you the response, I would
expect you to get the response. Are you sure you don't need to send
something first, i.e. a newline char?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|