// Default is no socket
$socketResource = FALSE;
- // Temporary resolve recipient field
- die(__METHOD__ . ': UNFINISHED!' . PHP_EOL);
- $unlData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+ // Resolve recipient (UNL) into a handler instance
+ $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
+
+ // Get UNL data
+ $unlData = $handlerInstance->getUniversalNodeLocatorData();
// Make sure it is a valid Universal Node Locator array (3 elements)
- assert(count($unlData) == 3);
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Checking ' . count($this->getAllSockets()) . ' socket(s),unlData[0]=' . $unlData[0] . ',unlData[1]=' . $unlData[1] . ' ...');
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Checking ' . count($this->getAllSockets()) . ' socket(s),unlData[' . UniversalNodeLocator::UNL_PART_ADDRESS . ']=' . $unlData[UniversalNodeLocator::UNL_PART_ADDRESS] . ',unlData[' . UniversalNodeLocator::UNL_PART_PORT . ']=' . $unlData[UniversalNodeLocator::UNL_PART_PORT] . ' ...');
// Default is all sockets
$sockets = $this->getAllSockets();
// Get
// If the "peer" IP and recipient is same, use it
- if ($peerIp == $unlData[0]) {
+ if ($peerIp == $unlData[UniversalNodeLocator::UNL_PART_ADDRESS]) {
// IPs match, so take the socket and quit this loop
$socketResource = $socketArray[self::SOCKET_ARRAY_RESOURCE];