public function connect($host, $port)
{
if (!empty($this->connection)) {
fclose($this->connection);
$this->connection = NULL;
}
$socket = fsockopen($host, $port, $errno, $errstr);
if (!$socket) {
$this->reportError('Connection error: ' . $errno . ':' . $errstr);
return false;
}
$this->connection = $socket;
return $socket;
}