Re: Ping+Port Routine?



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



Relevant Pages

  • tcp 139 or 445
    ... client open a tcp/445 socket. ... Packet: Session Request ...
    (microsoft.public.windows.server.networking)
  • Re: Protocol over TCP
    ... >> - On receiving, bytes are received asynchronously by calling the Socket ... >> RichTextBox and then clears it for the next packet. ... packet contents on the client app’s RichTextBox, ...
    (microsoft.public.dotnet.general)
  • Re: Ping+Port Routine?
    ... >> see a response packet appear on the client. ... >> 2) Write to socket. ... >> 3) Client gets response back from server. ...
    (comp.lang.php)
  • Re: Lost data on socket - Can we start over politely?
    ... >>server) and mini client. ... > find the application level packet lengths and a first internal packet ... > reading from the socket. ...
    (comp.lang.perl.misc)
  • Re: threads check socket
    ... What means an "open socket"? ... when the client closes the connection gracefully, you get an empty string '' when reading from the socket. ... If the client loses the connection abruptly you get no indication of that. ... Don't want it too fast or slow for the game server. ...
    (comp.lang.python)