Source for file echo-server.php
Documentation is available at echo-server.php
* Simple TCP echo server (localhost:9876)
* $Id: echo-server.php,v 1.5 2004/04/25 16:31:19 mike Exp $
require_once 'System/Socket/Creator.php';
* Create a System_Socket_Listener object with the spcified options passed
* through to the underlying System_Socket. Used options are typical for
$srv = &System_Socket_Creator ::createListener (
// just check if we actually got a System_Socket_Listener
if (PEAR ::isError ($srv)) {
// this array will hold already seen connection IDs
* We leave the loop when the listener gets closed
while ($srv->hasSocket ) {
* Fetch exceptional clients - this should rather never happen, though.
$excp = &$srv->getExceptionalClients ();
while ($conn = &$excp->shift ()) {
echo "\nExceptional Client: " . $conn->getID () . "\n";
* We first select writable clients to show a short greeting and usage
* message. System_Socket_Listener::getWritableClients() returns a
* System_Socket_ConnectionPool object like its counterparts for
* readable and exceptional clients.
$write = &$srv->getWritableClients ();
* Shift one client connection after another and check if we have already
* seen it before; otherwise display a short usage message.
while ($conn = &$write->shift ()) {
if (!isset ($seen[$conn->getID ()])) {
$conn->writeLine ('Type "exit" to quit or "stop" to stop the server');
$seen[$conn->getID ()] = true;
* Now read a line from the clients and write received data back. If we get
* a "exit" disconnect the client and if we get a "stop" shutdown the server.
$read = &$srv->getReadableClients ();
while ($conn = &$read->shift ()) {
$line = $conn->readLine ();
Documentation generated on Mon, 11 Mar 2019 10:15:56 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|