Client-Server model

From Artificial Neural Network for PHP
Revision as of 22:03, 14 January 2008 by Thwien (talk | contribs) (New page: == Server implementation == <source lang="php"> require_once 'ANN/ANN_Network.php'; require_once 'ANN/ANN_Server.php'; class ANN_MyServer extends ANN_Server { // ***********************...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Server implementation

require_once 'ANN/ANN_Network.php';
require_once 'ANN/ANN_Server.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_Network.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();