# Socket Help

**URL:** <https://forum.kirupa.com/t/socket-help/263732>\
**Category:** programming\
**Created:** [June 18, 2008, 7:28pm UTC](https://forum.kirupa.com/t/socket-help/263732 "2008-06-18T19:28:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grosie](https://avatars.discourse-cdn.com/v4/letter/g/9fc348/32.png) [@Grosie](https://forum.kirupa.com/u/Grosie)\
**Post date:** [June 18, 2008, 7:28pm UTC](https://forum.kirupa.com/t/socket-help/263732/1 "2008-06-18T19:28:57Z")

</div>

Hi, first post, but I have a socket question.  
I have written this PHP script and am executing it through a .bat file.

```php
#!/user/local/bin/php -q
<?php
 set_time_limit(0);
 
 $address = '127.0.0.1';
 $port = 9000;
 
 $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
 socket_bind($sock, $address, $port) or die('could not bind to address');
 socket_listen($sock, 5);
 
 $client = socket_accept($sock);
 socket_write($client, "Welcome fo-shizzles!
\r");
 
 $input = socket_read($client, 1024, PHP_BINARY_READ);
 
 $output = "Welcome to my PHP socket server. You sent me: $input
\r";
 
 socket_write($client, $output);
 
 socket_close($client);
 socket_close($sock);
?>

```

When I run & connect, it is fine, yet it returns the answer message & closes the connection when I type the first response character (no matter what it is)

What can I do?
