[Gllug] OT: reading from a socket in php

Robert McKay robert at mckay.com
Wed Oct 6 11:13:27 UTC 2010


On Wed, Oct 6, 2010 at 6:14 AM, <salsaman at xs4all.nl> wrote:

> I should explain a bit more perhaps. The php script sends a trigger to a
> running process which makes the process open a send port on udp 9998. The
> php script should then connect to the other end of the socket and read the
> return data which is being sent. The data is terminated with a NULL byte.
>

> Data can be read using nc -l -u 9998, and via a perl script. Tcpdump also
> shows the process responding with 6 bytes on udp 9998.
>

The socket you create and connect to port 9998 is expecting to receive
packets FROM another socket on localhost using a source port of 9998. The
packets should come from localhost:9998 and go to
localhost:<ephemeral-source-port>.

The ephemeral source port is assigned randomly from the free pool of ports.
The way this code is written the 'server' side of the connection should be
sending traffic to this randomly assigned ephemeral source port. I expect
that you probably aren't doing this. Most likely you are sending the traffic
to localhost:9998 - but this is the source not the destination of your php
client.

Most likely what you should do is use

http://php.net/manual/en/function.socket-bind.php

where you are using sock_connect() so that the socket expects to receive
traffic going to port 9998 instead of traffic coming from port 9998.

Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20101006/07fe3463/attachment.html>
-------------- next part --------------
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list