Location: PHPKode > scripts > pserver > chat.php
<?
/**
 * Chat PHP
 *
 * Thiss Class in a example of a Server create using class pserver
 *
 * @package pserver
 * @subpackage pserver.example
 * @author Pedro Vargas (hide@address.com) http://deerme.org
 * @version 0.1
 * @licence GNU General Public License (GPL)
 */
require('pserver.class.php'); 

 
class chat extends pserver
{
		
	/**
	* Read data on the client
	*/
	function readData( $data , $client  )
	{
		$data = trim($data);
		
		// Read
		foreach( $this->clients as $k => $v )
		{
			if ( $v["socket"] != $client["socket"] )
			{
				if ( trim($data) != "" )
					$this->writeData( $this->colorshell(32,'[' . $client['ip'] . ']').$this->colorshell(37,' says: ' . $data) . "\r\n" , $v );
			}			
		}
	}
	
	/**
	* Write data on the client
	*/
	function writeData( $data , $client)
	{		
		if ( trim($data) != "" )
		@socket_write($client['socket'], $data );
	}	
	
	
	
	
}


$server = new chat('0','1000');
$server->msg_welcome = $server->colorshell(32,"Welcome to the Chat \n\r").$server->colorshell(37,'');
$server->start();

?>
Return current item: pserver