Client-Server model: Difference between revisions
From Artificial Neural Network for PHP
Line 35: | Line 35: | ||
try |
try |
||
{ |
{ |
||
$ |
$objNetwork = new ANN_Network; |
||
} |
} |
||
catch(Exception $e) |
catch(Exception $e) |
||
{ |
{ |
||
print 'Network could not be created'; |
print 'Network could not be created'; |
||
exit; |
exit; |
||
} |
} |
||
$ |
$arrInputs = array( |
||
array(0, 0), |
array(0, 0), |
||
array(0, 1), |
array(0, 1), |
||
Line 50: | Line 51: | ||
); |
); |
||
$ |
$arrOutputs = array( |
||
array(0), |
array(0), |
||
array(1), |
array(1), |
||
Line 57: | Line 58: | ||
); |
); |
||
$ |
$objNetwork->setInputs($arrInputs); |
||
$ |
$objNetwork->setOutputs($arrOutputs); |
||
$ |
$objNetwork = $objNetwork->trainByHost('username', 'password', 'http://example.tld/ANN_Server.php'); |
||
if($ |
if($objNetwork instanceof ANN_Network) |
||
$ |
$objNetwork->printNetwork(); |
||
</source> |
</source> |
Revision as of 12:59, 18 December 2008
Server implementation
require_once 'ANN/ANN_Loader.php';
class ANN_MyServer extends ANN_Server
{
// ****************************************************************************
/**
* @param string $strUsername
* @param string $strPassword
* @return boolean
*/
protected function checkLogin($strUsername, $strPassword)
{
// User-defined authentication by database for example
return ($strUsername == 'username' && $strPassword == 'password');
}
// ****************************************************************************
}
$objServer = new ANN_MyServer;
Client implementation
require_once 'ANN/ANN_Loader.php';
try
{
$objNetwork = new ANN_Network;
}
catch(Exception $e)
{
print 'Network could not be created';
exit;
}
$arrInputs = array(
array(0, 0),
array(0, 1),
array(1, 0),
array(1, 1)
);
$arrOutputs = array(
array(0),
array(1),
array(1),
array(0)
);
$objNetwork->setInputs($arrInputs);
$objNetwork->setOutputs($arrOutputs);
$objNetwork = $objNetwork->trainByHost('username', 'password', 'http://example.tld/ANN_Server.php');
if($objNetwork instanceof ANN_Network)
$objNetwork->printNetwork();