[Sussex] Setting up a socket - PHP/Fedora

Ronan Chilvers ronan at thelittledot.com
Wed Sep 14 08:37:53 UTC 2005


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_socket_2.php
Type: application/x-php
Size: 1238 bytes
Desc: not available
Url : http://mailman.lug.org.uk/pipermail/sussex/attachments/20050914/b50490b8/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: server3.php
Type: application/x-php
Size: 2282 bytes
Desc: not available
Url : http://mailman.lug.org.uk/pipermail/sussex/attachments/20050914/b50490b8/attachment-0001.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mailman.lug.org.uk/pipermail/sussex/attachments/20050914/b50490b8/attachment.pgp 


More information about the Sussex mailing list