# \[php\] socket functions

**URL:** https://forum.kirupa.com/t/php-socket-functions/72371
**Category:** programming
**Created:** [December 5, 2004, 6:09am UTC](https://forum.kirupa.com/t/php-socket-functions/72371 "2004-12-05T06:09:05Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![eirche](https://avatars.discourse-cdn.com/v4/letter/e/e95f7d/32.png) [@eirche](https://forum.kirupa.com/u/eirche)
#### Post date: [December 5, 2004, 6:09am UTC](https://forum.kirupa.com/t/php-socket-functions/72371/1 "2004-12-05T06:09:05Z")

</div>

```php

// simple socket server
$sock = socket_create(AF_INET, SOCK_STREAM, 0) or die();
socket_bind($sock, 'localhost', 22444) or die();
socket_listen($sock); 

$client = socket_accept($sock); 

socket_write($client, 'welcome');

$read = socket_read($client, 1024); // line A

socket_write($client, strtolower($read)); // line B

socket_close($client); 
socket_close($sock); 

```

i tested this with flash’s xmlsocket, under both php5.0.2 and php4.3.9. three scenarios  
**1** , without lines A and B, connected -\> connection lost. no ‘welcome’ message was recieved.

**2** , with line A no B, connected -\> waits client input -\> client inputs ‘hello’ -\> connection lost. no message was recieved.

**3** , with lines A and B, connected -\> waits client input -\> client inputs ‘hello’ -\> connection lost. recieved ‘welcomehello’.

this behaviour is certainly not what i have intended. i expect that flash client would receive a ‘welcome’ message even socket server is without lines A and B.

is there a fix for this?
