You are here: Re: Ping+Port Routine? « PHP Programming Language « IT news, forums, messages
Re: Ping+Port Routine?

Posted by Adam on 11/23/36 11:27

On Thu, 22 Sep 2005 11:23:15 -0500, Jerry Stuckle wrote:

>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?

Jerry - thanks for persevering with me on this one <g>. Yep - I'd read
that warning in the manual.

There's no problem with *writing* to the [opened] socket. Using a
packet sniffer, I can see the data go out and - what's more - I can
see a response packet appear on the client. This is what's happening:

1) Open socket (in client).
2) Write to socket (gets sent successfully to game server).
3) Client gets response back from server (socket still open).
4) Futile attempts to read the 67 bytes long incoming packet (!!).
5) Close socket (in client).

For step 4, I've tried fread, fgets .. all sorts - but it occurs to me
that this may be a PHP/OS related thing, as I've seen (in my Googling)
reference to a *read* socket bug in PHP in earlier builds for Win32.

Are you suggesting I send something [again] before steps 3,4? Is it a
*timing* problem? Either the PHP script isn't waiting long enough for
the incoming packet or the packet has beenand gone before the script
has had a chance to read it?

All examples I've tried using (eg. HTTP/port 80) seem to work fine - a
request gets sent and the response is processed properly and
displayed.

My setup is Apache/2.0.52 (Win32) PHP/4.3.9. I'll try running the
client script from a Linux machine.

Adam.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация