[Sussex] Setting up a socket - PHP/Fedora

Brendan Whelan b_whelan at mistral.co.uk
Wed Sep 14 11:34:55 UTC 2005


Ronan,

Thanks for the latest information. Unfortunately, the release of PHP I am
using does not support streaming and it is not a good time to try upgrading.
I will bear it in mind for future programs as it looks to be a sensible and
straightforward method.

I made correction to the socket_read and messages from the client were
received. However, the process still continued round the loop when no input
was being received. So I moved the socket_accept inside the loop and it
works fine.

The two programs are attached.

Once again, many thanks for your help.

Regards,  Brendan
----------------------------------------------------------------------------
----------------------------

----- Original Message -----
From: "Ronan Chilvers" <ronan at thelittledot.com>
To: "LUG email list for the Sussex Counties" <sussex at mailman.lug.org.uk>
Sent: Wednesday, September 14, 2005 9:36 AM
Subject: Re: [Sussex] Setting up a socket - PHP/Fedora


Hi Brendan

On Tue, 13 Sep 2005 15:04:55 +0100
"Brendan Whelan" <b_whelan at mistral.co.uk> wrote:

>
> 1. The server happily waits until it receives a request/message from
> the client but no actual text is received (obviously something is
> received as the server waits until it is triggered by the message
> from the client.)

Just a syntax error in the code:

$received = socket_read($conn, $message_in, 4096);

should be

$received = socket_read($conn, 4096);

:-)

>
> 2. The server doesn't wait for the next request but simply goes
> around the loop i.e. the socket_read is always set after receiving
> the first message. As a consequence the client only receives on,
> long, message.

I've tweaked the server script again.  It now seems to work right
here.  I've also put in a loop which allows the server to continue
serving connections after each one closes.  Have a look and you'll see
what I mean.  I've also attached an example of using streams
(server3.php) to do the same thing, which I find a much cleaner and
simpler way of doing things.  The stream functions take care of socket
creation and management for you.  I have broken up things into
functions which makes things easier to manage.  I've put in some
comments for you so you can see what things are supposed to be doing.
Hope its clear.

Any problems, drop me a line.

Cheers

Ronan



----------------------------------------------------------------------------
----


> _______________________________________________
> Sussex mailing list
> Sussex at mailman.lug.org.uk
> Sussex LUG Website: http://www.sussex.lug.org.uk/
> http://mailman.lug.org.uk/mailman/listinfo/sussex
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_socket_2.php
Type: application/octet-stream
Size: 1481 bytes
Desc: not available
Url : http://mailman.lug.org.uk/pipermail/sussex/attachments/20050914/9a8b8787/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_send_message_2.php
Type: application/octet-stream
Size: 518 bytes
Desc: not available
Url : http://mailman.lug.org.uk/pipermail/sussex/attachments/20050914/9a8b8787/attachment-0001.obj 


More information about the Sussex mailing list