Client-Server model: Difference between revisions

From Artificial Neural Network for PHP
Line 31: Line 31:


<source lang="php">
<source lang="php">
require_once 'ANN/ANN_Network.php';
require_once 'ANN/ANN_Loader.php';


try
try

Revision as of 18:19, 16 December 2008

Server implementation

require_once 'ANN/ANN_Loader.php';

class ANN_MyServer extends ANN_Server
{
// ****************************************************************************

/**
 * @param string $username
 * @param string $password
 * @return boolean
 */

protected function checkLogin($username, $password)
{
// User-defined authentication by database for example

return ($username == 'username' && $password == 'password');
}

// ****************************************************************************
}

$server = new ANN_MyServer;

Client implementation

require_once 'ANN/ANN_Loader.php';

try
{
  $network = new ANN_Network;
}
catch(Exception $e)
{
  print 'Network could not be created';
  exit;
}

$inputs = array(
	array(0, 0),
	array(0, 1),
	array(1, 0),
	array(1, 1)
);

$outputs = array(
	array(0),
	array(1),
	array(1),
	array(0)
);

$network->setInputs($inputs);

$network->setOutputs($outputs);

$network = $network->trainByHost('username', 'password', 'http://example.tld/ANN_Server.php');

if($network instanceof ANN_Network)
  $network->printNetwork();