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

Posted by Adam on 09/26/05 16:57

On Mon, 26 Sep 2005 06:59:08 -0500, Jerry Stuckle wrote:

>Adam wrote:
>> Still no luck :-((
>>
>> I have Ethereal running on both client and server. Both versions
>> confirm that:
>>
>> 1) A request goes out to the server on port 2934. This is around 70
>> bytes: A header plus around 30 bytes of data.
>> 2) The server responds with a welcome of around 120 bytes.
>> 3) This packet duly arrives at the client.
>>
>> OK - now to the code. I've tried every combination of socket connect &
>> write, streams .. you name it ...but here are my two main variations:
>>
>>
>> // Set up the connection ===================
>> $remote_host = 'udp://192.168.1.126';
>> $remote_port = 2934;
>> $timeout = 1;
>>
>> // This is the outgoing msg (in hex) ==========
>> $hello =
>> "\x20\x00\x09\x42\x46\x4f\x31\x00\x00\x00\x00\x01\x83\x05\x07\x0d\x12";
>>
>> // This part embeds the client's IP address (in hex, backwards!)
>> // This is what the connecting flight sim appears to send
>> $hello .="\x03\x01\xa8\xc0";
>>
>> // The rest of the data packet:- (sim version etc).
>> $hello .= "\x03\x84\x0f\x87\x12\x02\x00\x00";
>>
>> // The returned data (I should be so lucky!) =====
>> $ret = '';
>>
>> // Open the socket ================
>> $socket = fsockopen($remote_host, $remote_port, $errno, $errstr,
>> $timeout);
>> if (!$socket) {
>> echo "Connection Failed - Please check manually."; }
>> else {
>> // Send the packet ===
>> fputs($socket, "$hello");
>> // fputs($socket, "$hello\r\n"); // Try with a return? ===
>>
>> echo "Sent to <b>$remote_host:$remote_port</b><br>";
>>
>> // So far so good ... the packet gets received
>> // by the server (confirmed by sniffer) ...
>> // and a reply gets sent to the client IP+port ..
>>
>> //... BUT ... neither of these appear to work =======
>> //$ret = fgets($socket, 64);
>> $ret = fread($socket, 2048);
>> // Tried all sorts values from 1 to 2048 =====
>>
>> echo "[" . $ret . "]";
>> fclose($socket);
>> };
>> echo "<hr>Closed";
>>
>> That's it! H-E-L-P !!! I wonder whether you/anyonecan shed any light
>> on this!
>>
>> Adam.
>
>
>Adam,
>
>Let's back up a little. I'm wondering if we're looking at the wrong
>problem.
>
>A couple of thoughts here. First of all, where are you running the
>sniffer? Is it on this machine, or somewhere upstream?

I've got Ethereal running on both machines:

1) Client: Linux - running the PHP script. No firewall.
2) Server: WinXP - running the sim in multiplayer mode. Firewall in
place (Norton PFW) but this server connects OK to other XP machines
running the sim in client mode.

>Also, are you using a firewall or a router anyplace? If so, are they
>set up properly to pass the incoming data onto your program?

The router only sits between the network and the ADSL.

Anyway - I can *see* the packets leaving/arriving on each machine - so
I think the firewall thing is OK. The packets appear addressed
properly, and contain data.

Having done a fair bit of googling around, it seems PHP's sockets
implementation is a bit quirky. All sorts of oddities come into the
equation - the "magic_quotes" setting, stream_set_blocking and so on.

I could paste the dumps of each packet if that helps any.

Over to you, Mastah! <g>.

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

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