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

Posted by Jerry Stuckle on 10/17/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
==================

 

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

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