public function testClientRemove() { $socket = new Socket(); $socket->bind('127.0.0.1', 22143); $socket->listen(); $server = new Server('', 0); $server->setLog(new Logger('test_application')); $server->init(); $client = $server->clientNew($socket); $server->clientRemove($client); #\Doctrine\Common\Util\Debug::dump($server); $this->assertTrue($client->getStatus('hasShutdown')); $server->shutdown(); }
public function connect($uri, $clientActions = array()) { $this->log->debug('connect: ' . $uri); $isBridgeChannel = false; $onode = null; $uriConnect = null; $bridgeTargetUri = null; if ($this->getSettings()->data['node']['bridge']['client']['enabled']) { if ($this->getTable()->getNodesNum()) { $onodes = $this->getTable()->getNodesClosestBridgeServer(1); if (count($onodes)) { $onode = array_shift($onodes); $this->logColor('debug', 'connect found bridge server: ' . $onode->getIdHexStr(), 'yellow'); $isBridgeChannel = true; $bridgeTargetUri = $uri; } else { $this->logColor('debug', 'connect: no bridge server found', 'yellow'); } } else { $this->logColor('debug', 'connect: no nodes available', 'yellow'); } } if (!$onode) { $this->log->debug('connect find by uri: ' . $uri); $onode = $this->getTable()->nodeFindByUri($uri); } if ($onode) { $this->log->debug('connect onode: ' . $onode->getIdHexStr() . ' ' . $onode->getUri()); $onode->incConnectionsOutboundAttempts(); $uriConnect = $onode->getUri(); } else { $this->log->debug('connect: old node not found'); $uriConnect = $uri; } try { if (is_object($uriConnect)) { if ($uriConnect->getScheme() == 'tcp') { if ($uriConnect->getHost() && $uriConnect->getPort()) { $socket = new Socket(); $connected = false; $connected = $socket->connect($uriConnect->getHost(), $uriConnect->getPort()); $client = null; $client = $this->clientNewTcp($socket); $client->setStatus('isOutbound', true); if ($isBridgeChannel) { $client->setStatus('bridgeServerUri', $uriConnect); $client->setStatus('bridgeTargetUri', $bridgeTargetUri); $client->bridgeActionsAdd($clientActions); $this->logColor('debug', 'bridge actions: ' . count($clientActions), 'yellow'); } else { $client->setStatus('isOutbound', true); $client->actionsAdd($clientActions); } if ($client && $connected) { $client->sendHello(); return $client; } } } else { $this->log->warning('connection to /' . $uriConnect . '/ failed: invalid uri scheme (' . $uriConnect->getScheme() . ')'); } /*elseif($uriConnect->getScheme() == 'http'){ $client = $this->clientNewHttp($uriConnect); $client->actionsAdd($clientActions); return true; }*/ } else { $this->log->warning('connection to /' . $uriConnect . '/ failed: uri is no object'); } } catch (Exception $e) { $this->log->warning('connection to ' . $uriConnect . ' failed: ' . $e->getMessage()); } return null; }